On Thu, 4 Jan 2007, Mr.Cashe wrote: > But I have found this draft: > http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf > > Page 59, $6.3.2.3.1 says: "A pointer to void may be converted to or from a > pointer to any incomplete or object type. A pointer to any incomplete or > object type may be converted to a pointer to void and back again; the result > shall compare equal to the original pointer"
This just means that after this code: void * p1; char * p2; void * p3; p2 = p1; p3 = p2; that p3 == p1 is always true. > Page 48, $6.2.5.26 says: "A pointer to void shall have the same > representation > and alignment requirements as a pointer to a character type (*The same > representation and alignment requirements are meant to imply > interchangebility as arguments to functions, return values from functions, > and members of unions)" This means that in the above code p1, p2, and p3 would also have an identical pattern of bits. It does not imply that any arithmetic applied to them would give identical results. > Is it still meant the increment code in my first post may not work? What are > you think about? Take a look at question 11.24 "Why can't I perform arithmetic on a void * pointer" in the C FAQ (available at http://c-faq.com among other places). There you can find further citations to specific subclauses of the C standard that define this behaviour. It worked as you expected with GCC because GCC treats this case as a special extension. From the current (4.1.1) GCC manual: 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. Of course, the drawback to using an extension is that your code becomes less portable. Erik ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sdcc-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sdcc-user
