Re: is this correct C? (char*)spm += spm->partitionMapLength;
- From: Johannes Bauer <dfnsonfsduifb@xxxxxx>
- Date: Fri, 30 Nov 2007 17:26:28 +0100
O_TEXT schrieb:
gcc answers no:
./a.out
spm : 0x2b3e202a8ca0
spm : 0x2b3e202a8ca5
spm : 0x2b3e202a8ccd
int main()
{
long *spm;
printf ("spm : %p \n", spm );
spm = ( long *) ((char*)spm + 5);
printf ("spm : %p \n", spm );
spm += 5;
printf ("spm : %p \n", spm );
return 0;
}
In the first example, spm is increased by 5 * sizeof(char), i.e. 5
bytes. In the second example, spm is increased by 5 * sizeof(long), i.e.
whatever it is in your implementation (I'm too lazy to calculate).
Pointer arithmetic is dependant on the type the pointer points to.
Greetings,
Johannes
--
"Viele der Theorien der Mathematiker sind falsch und klar
Gotteslästerlich. Ich vermute, dass diese falschen Theorien genau
deshalb so geliebt werden." -- Prophet und Visionär Hans Joss aka
HJP in de.sci.mathematik <4740ad67$0$3811$5402220f@xxxxxxxxxxxxxxx>
.
- References:
- Re: is this correct C? (char*)spm += spm->partitionMapLength;
- From: Spiros Bousbouras
- Re: is this correct C? (char*)spm += spm->partitionMapLength;
- From: O_TEXT
- Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Prev by Date: Re: memcat fn
- Next by Date: Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Previous by thread: Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Next by thread: Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Index(es):