B
Barry Schwarz
You can interpret it as an array of unsigned char and print the values
(in, say, hexadecimal).
If you can't cast it to void*, now can you cast it to unsigned char *?
<<Remove the del for email>>
You can interpret it as an array of unsigned char and print the values
(in, say, hexadecimal).
CBFalconer said:The normal integer promotions are another matter, and occur for
all parameters passed to any functions. They can NEVER lose
information, and serve to keep the stack (assuming there is a
stack) properly aligned, among other things. Thus you cannot pass
a char, it is always promoted to int. You can, however, tell
printf how to interpret that int. Similarly you can't pass a
short, or a float, without promotions.
Yes, you cannot do sizeof on a function pointer.
BTW - are there any known implementations where function pointers
cannot be converted to (void *) and back ?
In said:You can interpret it as an array of unsigned char and print the values
(in, say, hexadecimal).
No it's not.
In the absence of a printf() format specifier, you need
unsigned char buff[sizeof( fptr )]; /* will it choke on sizeof(main)?*/
^^^^memcpy(buff, main, sizeof(buff));
In said:If you can't cast it to void*, now can you cast it to unsigned char *?
In said:BTW - are there any known implementations where function pointers
cannot be converted to (void *) and back ?
I think that qualifies as an instance of the old "All world is a VAX"
syndrom
Sure, our personal computers are blessed by flat memory models the last
few years but C is not a language for PC-or-greater programming. A lot
of embedded systems still use segmented memory models.
Barry said:If you can't cast it to void*, now can you cast it to unsigned char *?
Keith Thompson said:You can interpret it as an array of unsigned char and print the values
(in, say, hexadecimal).
In said:Compared to what the committee members had to pay in order to cover their
own expenses just to be on the Standard committee, we're getting a bargain
;-)
No, it is not.Sweety said:hi,
Is main function address is 657.
its show in all compiler.
My compiler and linker package allows me to place thetry it & say why?
Barry said:Are you saying that calling a von-variadic function with a proper
prototype in scope will still have char, short, and float promoted?
In said:Dan Pop wrote:
| You can, if you assign it first to a pointer to function, which is an
| ordinary object whose address can be converted to unsigned char * (or
| even to void *, but this doesn't help, in context):
|
| fptr foo = main;
| unsigned char *p = (unsigned char *)&foo;
|
| Now, you can use p to access the representation of the value of foo.
OK, so now I understand.
Anyone want to tell me /why/ the standard makes such contortions necessary?
The C standard requires only that memory be "locally flat" (that
is, there can be regions with discontinuities or overlap, as is
the case on the 80x86 with its 16-byte "segments" addressing up to
1 megabyte of RAM, with the CS, DS, ES, and SS registers "overlapping"
data pointers in that odd manner, so that you get phys_addr =
(segment << 4) + offset).
This has nothing to do with the cast, though, whose purpose is
to make the types match. The underlying representation of any
given value is allowed to depend on its type. Just as 1.0f (a
32-bit float) and 1 (a 32-bit int) have different bit patterns
even though they have the same value, it is possible that:
int *ip;
void *vp;
...
vp = ip;
puts a different bit pattern into vp than is in ip.
In said:Note I did (reluctantly) accept reality two sentences later.
Do VAX people really think that way? The only time I've worked near a VAX
was at MIT LCS, and while folks there were excited to get one (1978), I
think they did pretty well keeping an open mind about other architectures.
....The famous expression refers to people who have never used or programmed
on anything but VAXen.
Myes, you can; but where pointers are sufficiently unusual for the above
not to work, is that likely to give usefully interpretable values? Maybe
so.
CBFalconer said:As usual, it depends.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.