Walter Roberson said:
I went looking at the ANSI C89 reference thinking that was wrong, but
I was mistaken, and learned somethings along the way. It was not, though,
about the obvious question of whether a number can be converted to a
pointer.
What I was looking at was whether the 0xFFF0000E constant had the
right type: I was thinking "Ah, but if int is only 16 bits, won't
that constant get truncated, seeing as it does not have a suffix?".
The C89 standard indicates, though, that an integer constant has
the smallest type out of a given list that will fit the numeric value.
And what I also found in the C89 standard was that the type list
considered
is different for decimal constants than for octal or hex constants.
I had thought that all forms of constants were equivilent, but they
aren't.
On 16 bit int 2's complement systems, the decimal constant 65535
would be represented as type long int, but the hex constant 0xFFFF
would be represented as type unsigned int. That would imply that,
for example, on such a system, sizeof(65535) > sizeof(0xFFFF).
There's gotta be a good Obfuscated C trick in there somewhere ;-)
Hey Thanks for that Walter, this is so interesting, and while trying the
solution, the compiler croaks for NO apparent reason at least to me,
1 unsigned char valIsaDot = 0;
2 unsigned char valBootVer = 0;
3
4 unsigned char *pBootVer = (unsigned char *)0xFFF0000E;
5 valBootVer = *pBootVer;
6
7
8 unsigned char *pBootDot = (unsigned char *)0xFFF0000F;
9 valIsaDot = *pBootDot;
The compiler says error at line 8 near 'unsigned' If line 8 and 9 are
removed, it compiles fine. There is nothing wrong with the spelling, it
simply wont allow this. On line 7 I add some extra task like int foo =0;
doesnt matter. If I take out the '=' on line 8 and have only the
definition? same error, line 8 near unsigned.
1// unsigned char valIsaDot = 0;
2// unsigned char valBootVer = 0;
3
4 unsigned char *pBootVer = (unsigned char *)0xFFF0000E;
5 unsigned char valBootVer = *pBootVer;
6
7
8 unsigned char *pBootDot = (unsigned char *)0xFFF0000F;
9 unsigned char valIsaDot = *pBootDot;
Do this? it compiles fine and works exactly right. (thanks again btw)
If there are no syntax errors, why does it refuse to accept the line 8
command before?