Re: Is it a Bug? (void*)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is not a bug, it's a feature :-)

http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Pointer-Arith.html#Pointer-Arith

>>>
5.17 Arithmetic on void- and Function-Pointers
 In GNU C, addition and subtraction operations are supported on pointers
to void and on pointers to functions. This is done by treating the size
of a void or of a function as 1.
A consequence of this is that sizeof is also allowed on void and on
function types, and returns 1.
The option -Wpointer-arith requests a warning if these extensions are used.
<<<


Daniel


Duft Markus wrote:
> Hi
> 
> I'm porting lots of stuff to windows (i know, *arg*...) and while doing
> so i found something interesting in a C Source file:
> 
>  void* myptr = (void*)otherptr + 1;
> 
> Which doesn't compile with the microsoft compiler (error: void*: unknown
> size). Now i think, that microsoft is right in that case, and that void
> really has an unknown size.
> 
> Since the "+ 1" should add something like "one times sizeof type" to the
> pointer, what should the compiler add when void is encountered? I think
> the above is wrong and dangerous. Should the compiler catch this? With
> C++ gcc prints an error and exits, but because of type conversions, not
> because of the addition.
> 
> I attached a small test program, which demonstrates this (maybe bug...
> ;o)).
> 
> Should i officially report this issue?
> 
> Cheers, Markus


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux