Re: Missing prototype and resulting coredump



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
.



Relevant Pages

  • Re: Missing prototype and resulting coredump
    ... If i am not putting the function prototype of a function ... returning a pointer, i get a core dump.Though this will happen less ... If your compiler does not issue a diagnostic for this code, ... The code has undefined behavior. ...
    (comp.lang.c)
  • Re: GDBM prototype magic.
    ... functions of gdbm work with GDBM_FILE pointer (which is returned by ... 1) to let the compiler check on ... this definition is inconsistent with the prototype. ... want to expose the gdbm_file_info structure in gdbm.h so that he can ...
    (comp.lang.c)
  • Re: gcc knows about malloc()
    ... Using malloc without a prototype in scope. ... The call uses a function pointer whose type almost ... compiler has to know the type of the original pointer in order to ...
    (comp.lang.c)
  • Re: How to check for already running program?
    ... Although the underlying reason for needing the cast is essentially the same ... NULL as an argument where a pointer is expected. ... compiler issue a warning for calls to functions without a prototype. ...
    (comp.unix.programmer)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>>would clean up a lot of code by eliminating the pointer dereferences. ... >>>guaranteed by the standard and should not be relied on. ... >>>You can try the GNU C compiler available on mingw or cygwin. ... >>>the Constraints are then both operands shall have arithmetic type. ...
    (comp.soft-sys.matlab)