473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Missing prototype and resulting coredump

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
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
Rakesh UV

Oct 18 '07 #1
3 1926
Rakesh UV wrote:
I know that putting the prototype would solve the problem, but
unfortunately
there are huge number of files
Time to warm up your favorite text editor. Can't you add the
prototype(s) to an appropriate header and the add said header to all the
files with a script?

Porting smelly code from 32 to 64 bit is fraught with problems, lack of
prototypes is one you can easily fix.

--
Ian Collins.
Oct 18 '07 #2
On Thu, 18 Oct 2007 06:31:17 -0000, Rakesh UV <uv******@gmail.com>
wrote in comp.lang.c:
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]) ;
If your compiler does not issue a diagnostic for this code, either it
is badly broken, or you did not tell it to operate as an actual C
compiler. A diagnostic is required.
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
And what if 64 bit addresses are returned in a completely different
manner and you are really losing all 64 bits of the address?

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
Why? The code has undefined behavior. It is wrong. It is garbage.
that i can preserve the actual address returned
or
What if 64 bit long long is returned in a different register than a 64
bit pointer?
do we have any other way in C to make it right
There is no way in C to make it right. The code has undefined
behavior. If a function returns anything other than an int, and you
do not have a prototype in scope, they there is no way to avoid
undefined behavior. Period. The only way to make it right is to have
a prototype in scope. Period.
I know that putting the prototype would solve the problem, but
unfortunately
there are huge number of files
That's why there are programs that can search and replace in huge
numbers of files.
Rakesh UV
Don't EVER port code this bad to another platform without fixing it.

And reeducate the programmers who wrote it. If they won't accept
reeducation, fire them.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Oct 19 '07 #3
On Thu, 18 Oct 2007 06:31:17 -0000, Rakesh UV <uv******@gmail.com>
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
Nov 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nrhayyal | last post by:
hi guys, i am using AIX 5.2 OS and working on c++ and the compiler is gcc-3.3.2 i have a c++ application which was developed on solaris. now i am porting it to AIX. most of my modules work fine....
8
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the...
8
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
2
by: Rafal 'Raf256' Maj | last post by:
Hi, how can I manualy dump a backtrace and/or coredump to a file and/or console? Can I do it without aborting the program? --...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
11
by: shypen42 | last post by:
Hi all, I'm very confused by the relation between "prototype" and that "Prototype.js" library that seems to be used quite a lot (not by knowledgeable people from this group if I understood...
13
by: tomy | last post by:
Hi all: There is an amazing coredump in my C code, I was thinking it over and over... The code is simple as below: //************************************* const unsigned long int len =...
1
by: drnicwilliams | last post by:
The Prototype library gives us the $() operation for converting a DOM element id into the DOM element: $('element-id'). It also appends a bunch of functions to the resulting object. Sometimes...
83
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.