Re: Arithmetic on function address
From: Stephen Biggs (Spammers_at_AreLowLifes.com-INVALID-MUNGED)
Date: 04/23/04
- Next message: Keith Thompson: "Re: Rob Pike's simple Include rule"
- Previous message: Jakob Bieling: "Re: Opinion) Overuse of symbolic constants"
- In reply to: Eric Sosman: "Re: Arithmetic on function address"
- Next in thread: Eric Sosman: "Re: Arithmetic on function address"
- Reply: Eric Sosman: "Re: Arithmetic on function address"
- Reply: Arthur J. O'Dwyer: "Re: Arithmetic on function address"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Apr 2004 19:51:39 +0000 (UTC)
Eric Sosman <Eric.Sosman@sun.com> wrote in
news:4089560E.986D134A@sun.com:
> Stephen Biggs wrote:
>>
>> Given this code:
>> void f(void){}
>> int main(void){return (int)f+5;}
>>
>> Is there anything wrong with this in terms of the standards?
>
> Yes and no. The Standard permits you to cast a pointer
> value (even a function pointer value) to an integer, but it
> does not guarantee that the result is useful or even usable.
But, it then should allow you to add a value to that integer, as the
code says, no? Is this what you mean by no guarantees of it being
usable?
>
>> Is this legal C code?
>
> Legal but useless.
Ok, fine... I agree completely that it is useless, but shouldn't correct
code be generated for it?
>
>> One compiler I'm working with compiles this quietly, even with the
>> most stringent and pedantic ANSI and warning levels, but generates
>> code that only loads the address of "f" and fails to make the
>> addition before returning a value from "main".
>>
>> GCC "does the right thing".
>>
>> Is there something I'm missing?
>
> Your marbles, perhaps. ;-) What are you trying to
> accomplish with this ill-defined operation?
>
Thank you for that :)... I am not trying to accomplish anything besides
running the GCC testsuite on some other compiler that I am trying to
analyze. This is part of the testsuite and passes with GCC, no
problem... I was just wondering if this is a bug in the compiler that I
am trying to run on this code? I want to be sure that this should
generate code correctly before I cry "bug". That is, that it should
generate code to add the constant after the pointer is converted to an
integer.
Thanks for any help.
- Next message: Keith Thompson: "Re: Rob Pike's simple Include rule"
- Previous message: Jakob Bieling: "Re: Opinion) Overuse of symbolic constants"
- In reply to: Eric Sosman: "Re: Arithmetic on function address"
- Next in thread: Eric Sosman: "Re: Arithmetic on function address"
- Reply: Eric Sosman: "Re: Arithmetic on function address"
- Reply: Arthur J. O'Dwyer: "Re: Arithmetic on function address"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|