Re: is this correct C? (char*)spm += spm->partitionMapLength;
- From: O_TEXT <O_TEXT@xxxxxxxxx>
- Date: Fri, 30 Nov 2007 17:54:08 +0100
Spiros Bousbouras a écrit :
On Nov 30, 3:50 pm, O_TEXT <O_T...@xxxxxxxxx> wrote:Spiros Bousbouras a écrit :
On Nov 30, 1:00 pm, O_TEXT <O_T...@xxxxxxxxx> wrote:gcc 4.1 gives this error message (not a lvalue).is line 11 valid?No , line 11 is not valid C because the expression
if yes, is it equivalent to line 10?
1 typedef unsigned char uint8_t;
2 struct sparablePartitionMap
3 {
4 uint8_t partitionMapLength;
5 } __attribute__ ((packed));
6 void initialise(char *devicename)
7 {
8 struct sparablePartitionMap *spm;
9 spm += spm->partitionMapLength;
10 spm = ( struct sparablePartitionMap *) ((char*)spm +
spm->partitionMapLength);
11 (char*)spm += spm->partitionMapLength;
12 }
(char *)spm is not an lvalue.
I do not the requirment for a value to be a lvalue.
You're missing a verb here.
I do not know the requirment for a value to be a lvalue.
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;
}
This also evokes undefined behaviour so it
doesn't tell us much.
so you will prefer the first line of main?
gcc -E aaa.c
long titi[123];
long toto[200];
int f(long*p)
{
long *spm = p;
printf ("spm : %p %ld\n", spm , spm);
spm = ( long *) ((char*)spm + 5);
printf ("spm : %p %ld\n", spm , spm);
spm = p;
spm += 5;
printf ("spm : %p %ld\n", spm , spm);
printf (" \n");
}
int main()
{
f ( &(toto[0]) );
f ( 0 );
return 0;
}
../a.out
spm : 0x7fff0883ee70 140733336252016
spm : 0x7fff0883ee75 140733336252021
spm : 0x7fff0883ee98 140733336252056
spm : (nil) 0
spm : 0x5 5
spm : 0x28 40
.
- 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;
- From: Spiros Bousbouras
- Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Prev by Date: Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Next by Date: Re: Reading a table
- Previous by thread: Re: is this correct C? (char*)spm += spm->partitionMapLength;
- Next by thread: C/C++ on UNIX Developer required in Woodmead, Johannesburg
- Index(es):
Relevant Pages
|