From: SourceForge.net <no...@so...> - 2004-12-05 13:00:02
|
Bugs item #1079338, was opened at 2004-12-05 14:00 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1079338&group_id=599 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: HS_EMB_DIGI (hsack) Assigned to: Nobody/Anonymous (nobody) Summary: Address of a void ptr doesn't change Initial Comment: I read the RFE 905167 and wrote a short senseless program, it results in detecting a bug: sdcc -v SDCC : mcs51/ds390/pic16/TININative/xa51/ds400 2.4.7 #897 int *intptr; void *voidptr; char main (void) { int x[2] = {0,4711}; char res; voidptr = x; intptr = x; /* < voidptr++; // No warning, but o.k. since sizeof(void) == 0 */ voidptr += sizeof(int); // but here it's *NOT* incremented, too intptr++; res = (*(int *)voidptr == *intptr); // should be true return(res); } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1079338&group_id=599 |
From: SourceForge.net <no...@so...> - 2004-12-05 18:20:21
|
Bugs item #1079338, was opened at 2004-12-05 14:00 Message generated for change (Comment added) made by maartenbrock You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1079338&group_id=599 Category: None >Group: non bugs >Status: Closed >Resolution: Rejected Priority: 5 Submitted By: HS_EMB_DIGI (hsack) Assigned to: Nobody/Anonymous (nobody) Summary: Address of a void ptr doesn't change Initial Comment: I read the RFE 905167 and wrote a short senseless program, it results in detecting a bug: sdcc -v SDCC : mcs51/ds390/pic16/TININative/xa51/ds400 2.4.7 #897 int *intptr; void *voidptr; char main (void) { int x[2] = {0,4711}; char res; voidptr = x; intptr = x; /* < voidptr++; // No warning, but o.k. since sizeof(void) == 0 */ voidptr += sizeof(int); // but here it's *NOT* incremented, too intptr++; res = (*(int *)voidptr == *intptr); // should be true return(res); } ---------------------------------------------------------------------- >Comment By: Maarten Brock (maartenbrock) Date: 2004-12-05 19:20 Message: Logged In: YES user_id=888171 This is no bug. If you agree voidptr++ doesn't increment is ok, than you should know that voidptr+=sizeof(int) doesn't increment either. Sizeof(int) only returns a number, just like ++ means +=1. In this case 1 is the number. This number must be multiplied by the size of the object the pointer points to. In this case 0. If you want to use sizeof() to increment the pointer to the next object, it must be added to a char* casted version: voidptr = (char*)voidptr + sizeof(int); Hope this clarifies things ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1079338&group_id=599 |