Re: Missing prototype and resulting coredump
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Sat, 03 Nov 2007 16:50:26 -0700
On Thu, 18 Oct 2007 06:31:17 -0000, Rakesh UV <uvrakesh@xxxxxxxxx>
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
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
Even if there were such an option, your code would still invoke
undefined behavior. This is true anytime you cause the compiler to
make an assumption that is not valid. Why do you assume the compiler
will return a pointer using the same mechanism it uses to return an
integer? What is so onerous about providing a prototype that you are
willing to run this risk?
or
do we have any other way in C to make it right
I know that putting the prototype would solve the problem, but
unfortunately
there are huge number of files
That's what headers are for.
Remove del for email
.
- Prev by Date: Re: Meaning of memset (Was: Re: Assigning values to char arrays)
- Next by Date: Re: Mnemonic
- Previous by thread: beautiful girls will help you,why?check it out
- Next by thread: cannot read after \n using strtok()
- Index(es):
Relevant Pages
|