Join Now

Difference between the pointers in Carbide c++ and C++

Carbider | 17 October, 2007 16:11

One more difference between Carbide C++ and standard C++ that I found while porting is pointers maintaining.
If you have a pointer 'p'
void *p = other_pointer;
in C you can sum it up with integer value to walk through memory:
p += sizeof(uint8_t);
That is frequently used in BlueZ libraries.
But Carbide doesn't allow such manipulation motivating with:
"illegal operands 'void *' + 'unsigned int'"
That is because Carbide is more strict with types than C is.
So to move through memory I need that pointer 'p' would be a pointer to specific data type, not ‘void’.
I decided, 'p' should be a pointer to 'uint8_t' because it is used as type’s length to determine data’s displacement step.
So the final declaration looks like this:
uint8_t *p;;

p += sizeof(uint8_t);

Comments

Re: Difference between the pointers in Carbide c++ and C++

Sorcery-ltd | 18/10/2007, 12:07

Sorcery-ltd Hi Konstantine,

Just a quick note on terminology. Carbide C++ is a tool not a language. There is such a thing as Symbian C++ which has some restrictions compared to standard C++ (such as multiple inheritance only through Mixin classes) but in this case it is just a case of different compiler settings. On some compilers adding something to a void pointer will only give a warning (which might be supressed) and not an error. In general C compilers are less fussy about this sort of thing that C++ compilers by default.

Mark
(Sorcery)

Re: Difference between the pointers in Carbide c++ and C++

Carbider | 19/10/2007, 10:58

Carbider thanks for your note that carbide is not a language

Re: Difference between the pointers in Carbide c++ and C++

benjers | 18/10/2007, 13:03

Please note that Carbide itself is just an IDE. We are compiling our apps using Carbide IDE with 3 different compilers (x86, GCCE and ARMCC). They usually give different warnings and errors... So it's strictly related to the compiler, Carbide itself has very little to do with it.

Re: Difference between the pointers in Carbide c++ and C++

Carbider | 19/10/2007, 10:59

Carbider So, now I have to call it like Symbian C++, or GCCE C++?
thanks

Re: Difference between the pointers in Carbide c++ and C++

PushL | 18/10/2007, 19:39

Hi Konstantine,

This is a language thing. Neither C nor C++ allows pointer arithmetic on void pointers, as they can't be dereferenced (what's the size of void?). I suggest you check the C or C++ standard (you can find a free draft searching in google)

What you're referring to (at least from what you mention) is a gcc compiler extension, which treats void* like char*. You should be careful with such extensions, as it breaks portability in the best case (such as this).

David / PushL

Re: Difference between the pointers in Carbide c++ and C++

Carbider | 19/10/2007, 10:55

Carbider Yes, I thought so to, how we can make arithmetic with void.
But I thought it solves by "p += sizeof(uint8_t);"

Thanks for information about gcc compiler and "void*" to "char*" conversion. I'll try to search about this.

Re: Difference between the pointers in Carbide c++ and C++

jplauril | 19/10/2007, 10:20

This behaviour is perfectly standard for a C++ compiler. I guess you meant to compare C++ and C?

Re: Difference between the pointers in Carbide c++ and C++

Carbider | 19/10/2007, 10:51

Carbider It is quite possible that I really should write: "compare C++ and C", not C++, because BlueZ is written on C.
here, it is said that: "BlueZ project should follow the coding style of the Linux kernel"
http://www.bluez.org/development.html

But can it be C++ and C differ so much that we have to change a code

Re: Difference between the pointers in Carbide c++ and C++

Sorcery-ltd | 19/10/2007, 11:00

Sorcery-ltd Yes, most C code will compile with a C++ compiler but there are almost always some issues when moving between the two. For a large project you will often have to change code when moving between two versions of the same compiler!
You must login to post comments. Login
 
 
Powered by LifeType