> -----------
>
> char *shortfile(name)
> char *name;
> {
> int len,i;
> char *shortname;
>
> len = strlen(name);
> shortname = name;
> while (len != 0) {
> if(*(name+len)== '/') {
> shortname = name+len+1;
> break;
> }
> len--;
> }
> }
>
> -----------
>
>
> Notice that there is no return statement? I can only assume that the compilers
> for Sun and HP have `accidentally' optimized 'char *shortname' into the
> register which is used to return the result. The DECC compiler on the Alpha
> doesn't complain about this construction (do the others?), but the routine
> returns junk which causes a segmentation fault.
>
I have found that gcc -Wall does a better job of reporting problems than
the sun compiler. It returns the warning:
warning: control reaches end of non-void function
By the way the c rules state:
If no expression appears in the return statement, then no value is returned
from the function; this is always permitted, even if the function has a declared
return type other than void.
C, A Reference Manual, Samuel P. Harbison, etc Third Edition page 234.
The second edition of K&R page 26 has similar words.
This seems like a rather strange rule.
Marty Kraimer
- Navigate by Date:
- Prev:
Announcing ezcaIDL, a new extension Mark Rivers
- Next:
OMS driver bug? Ian Smith
- Index:
1994
<1995>
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Cute error in alh/file.c 415
- Next:
Announcing ezcaIDL, a new extension Mark Rivers
- Index:
1994
<1995>
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|