Operating System - HP-UX
1753483 Members
4082 Online
108794 Solutions
New Discussion юеВ

Re: aCC warnings when end of function reached without a return?

 
SOLVED
Go to solution
simon moore
New Member

aCC warnings when end of function reached without a return?

Hi There,

how can I get aCC (v 3.50) to warn when it encounters the following situation (no return).

Any help much appreciated.

Thanks

Simon


int f(int i)
{
if (42 == i)
{
return i;
}
else
{
cout << "not returning" << endl;
// return nothing
}
}
4 REPLIES 4
Antoniov.
Honored Contributor

Re: aCC warnings when end of function reached without a return?

Hi Simon,
a int function return always a value; in c (R&K and ANSI) doesn't exist NULL value for int.
However I use code like follow:

#define NULLINT 0x80000000
int f(int i)
{ if (i==42) /* Test my value */
return (i); /* return valid value */
else
return (NULLINT); /* invalid value */
}
In this example I suppose 32bit int; you could set a value 0x08 followed by zero until pad the size.
Also your caller code must be recognize the NULLINT value (for example):
i=f(10);
if (i==NULLINT)
/* here do noting */
If you ise ANSIC you could use macro MININT (if I remember);
Notice, in this way, negative vale ha min suca as positive value; for example using 16 bit int your valid value are -32678..32767; using my hint valid value are -32767..32767 because -32768 id NULL value.

H.T.H.
Antoniov
Antonio Maria Vigliotti
simon moore
New Member

Re: aCC warnings when end of function reached without a return?

I should add that I have a rather large code base and I need a compiler switch to detect this situation as the behaviour of what gets returned is not only 'undefined' but it is differently undefined in statically and dynamically linked programs.

Simon
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: aCC warnings when end of function reached without a return?

There is no pragma or switch to do this in aCC. Compiling with +w (full warnings) does not flag this as a warning either. Ironically, this would have been "duck soup" with lint but lint doesn't understand C++. You really nned a lint that speaks C++ and runs on HP-UX. One such lint is FlexeLint from Gimpel although it's not free:
http://www.gimpel.com/html/flex.htm

It would be quite easy to add a FlexeLint call to all your makefiles before invoking aCC.
If it ain't broke, I can fix that.
simon moore
New Member

Re: aCC warnings when end of function reached without a return?


Ironically, g++ -Wall -pedantic -ansi flags this, as does VC++.

Why doesn't aCC? It's infuriating!!!! And it took a helluva lot of time to track down the behavioural differenced between static and dynamic builds.

Can anyone from HP answer?

Thanks

Simon