|
|
Missing prototype and resulting coredump in 64 bit machines
Hi,
If i am not putting the function prototype of a function
returning a pointer, i get a core dump.Though this will happen less
probably on 32 bit machine
example
int main(int argc , char **argv)
{
char *base = basename(argv[0]) ;
printf("%s",base);
return 0;
}
The compiler assumes that basename is returning an int and thus we
loose 32 bit of the actual address, because pointer is 64 bit and
integer is 32 bit in 64 bit machines
I am working on
Os linux x86_64 2.6.9
Machine Hp
compiler gcc 3.46
Is there any option in GCC to make the default return value as long so
that i can preserve the actual address returned
Rakesh UV
|
|
0
|
|
|
|
Reply
|
uvrakesh (31)
|
10/18/2007 6:37:56 AM |
|
Rakesh UV wrote:
> Hi,
> If i am not putting the function prototype of a function
> returning a pointer, i get a core dump.Though this will happen less
> probably on 32 bit machine
Yes, that would be true [though technically, a 32-bit environment --
the machine/OS itself can be 64-bit and still have an application
using 32-bit pointers...]. Don't do that, most especially NEVER
forget to include the declaration for malloc() [and never cast
the result of malloc() to hide this type of warning]... since
that's one of the worst cases of "mangle a pointer into an int"
you can do...
>
> example
> int main(int argc , char **argv)
> {
> char *base = basename(argv[0]) ;
> printf("%s",base);
> return 0;
>
> }
>
> The compiler assumes that basename is returning an int and thus we
> loose 32 bit of the actual address, because pointer is 64 bit and
> integer is 32 bit in 64 bit machines
Right, because that's the C Standard.
http://c-faq.com/decl/implfdecl.html
>
> I am working on
> Os linux x86_64 2.6.9
Ok... you realize the "hpux" in the newsgroup name is for HP-UX,
not "Any *nix(-ish) running on HP hardware", right? ;)
> Machine Hp
> compiler gcc 3.46
>
> Is there any option in GCC to make the default return value as long so
> that i can preserve the actual address returned
I don't know -- but I honestly would hope not. What you're doing is
flat out *wrong*. Functions should have proper declaration in scope
before invocation. Don't try to make the tool fit your bad code... fix
the code.
Don
|
|
0
|
|
|
|
Reply
|
Don
|
10/18/2007 11:26:57 AM
|
|
> I don't know -- but I honestly would hope not. What you're doing is
> flat out *wrong*. Functions should have proper declaration in scope
> before invocation. Don't try to make the tool fit your bad
> code... fix the code.
Agreed. Fix the code.
rick jones
--
oxymoron n, commuter in a gas-guzzling luxury SUV with an American flag
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
|
|
0
|
|
|
|
Reply
|
Rick
|
10/18/2007 6:01:24 PM
|
|
|
2 Replies
159 Views
(page loaded in 0.107 seconds)
|
|
|
|
|
|
|
|
|