www.digitalmars.com         C & C++   DMDScript  

c++ - Code checking

reply SD <stephanedelaval wanadoo.fr> writes:
Hi,
I am using the C compiler with the maximum checking option I found, -A -w- 
-r.
However, the compiler does not check the possible errors as I would like, 
ie :
- I declared main() as returning a void, and the compiler did not complain.
- I declared a function returning an int, and I do not use return statement 
in the function body. Again, the compiler does not complain.
- I use a function without declaring the prototype. The compiler says 
nothing.

Is there a compiler option I have not seen, or the compiler does not make 
these controls ?

Thx
SD
Oct 05 2002
parent reply Larry Brasfield <larry_brasfield snotmail.com> writes:
In article <ann0hg$16cs$1 digitaldaemon.com>, 
SD (stephanedelaval wanadoo.fr) says...
 Hi,
 I am using the C compiler with the maximum checking option I found, -A -w- 
 -r.
 However, the compiler does not check the possible errors as I would like, 
 ie :
 - I declared main() as returning a void, and the compiler did not complain.
 - I declared a function returning an int, and I do not use return statement 
 in the function body. Again, the compiler does not complain.
 - I use a function without declaring the prototype. The compiler says 
 nothing.
 
 Is there a compiler option I have not seen, or the compiler does not make 
 these controls ?

If you want better compile-time checking, why not compile your C programs using the C++ compiler? It's been awhile since I used C very much, but I recall that the issues you object to were not errors according to the C language. Those and many other needless lapses were tightened up in C++. -- -Larry Brasfield (address munged, s/sn/h/ to reply)
Oct 05 2002
parent reply SD <stephanedelaval wanadoo.fr> writes:
Thk for the prompt reply.
You are suggesting a very good solution. However I used the -cpp option 
of the sc.exe dmars compiler, and it still have the same problem.
Is there another C++ compiler in the digital mars package ? Except for 
this flag, I have not seen any reference for it...
SD

 In article <ann0hg$16cs$1 digitaldaemon.com>, 
 SD (stephanedelaval wanadoo.fr) says...
 Hi,
 I am using the C compiler with the maximum checking option I found,
 -A -w- -r.
 However, the compiler does not check the possible errors as I would
 like, ie :
 - I declared main() as returning a void, and the compiler did not
 complain. - I declared a function returning an int, and I do not use
 return statement in the function body. Again, the compiler does not
 complain. - I use a function without declaring the prototype. The
 compiler says nothing.
 
 Is there a compiler option I have not seen, or the compiler does not
 make these controls ?

If you want better compile-time checking, why not compile your C programs using the C++ compiler? It's been awhile since I used C very much, but I recall that the issues you object to were not errors according to the C language. Those and many other needless lapses were tightened up in C++.

Oct 05 2002
parent reply bw <bw_member pathlink.com> writes:
In article <ann7mi$1cj9$1 digitaldaemon.com>, SD says...
 However, the compiler does not check the possible errors as I would
 like, ie :
 - I declared main() as returning a void, and the compiler did not
 complain. - I declared a function returning an int, and I do not use
 return statement in the function body. Again, the compiler does not
 complain. - I use a function without declaring the prototype. The
 compiler says nothing.



got version 8.29 ?
Oct 05 2002
parent reply SD <stephanedelaval wanadoo.fr> writes:
Yes, I have the latest available.



bw <bw_member pathlink.com> wrote in news:annuff$24fi$1 digitaldaemon.com:

 
 In article <ann7mi$1cj9$1 digitaldaemon.com>, SD says...
 However, the compiler does not check the possible errors as I would
 like, ie :
 - I declared main() as returning a void, and the compiler did not
 complain. - I declared a function returning an int, and I do not use
 return statement in the function body. Again, the compiler does not
 complain. - I use a function without declaring the prototype. The
 compiler says nothing.



got version 8.29 ?

Oct 06 2002
parent reply bw <bw_member pathlink.com> writes:
In article <anosh8$ke$1 digitaldaemon.com>, SD says...
Yes, I have the latest available.

 got version 8.29 ?


the 8.29 i have catches all those, don't understand why you're having trouble? /* testing for errors */ #include <stdio.h> void main(void) { func(); } int func() { } C:\cpp\my>sc -A -w- -r errs.c func(); ^ errs.c(8) : Error: function 'func' has no prototype errs.c(15) : Error: need at least one external def --- errorlevel 1 C:\cpp\my>sc -A -w- -r -cpp errs.c func(); ^ errs.c(8) : Error: function 'func' has no prototype } ^ errs.c(14) : Error: implied return of func at closing '}' does not return value errs.c(15) : Error: need at least one external def --- errorlevel 1
Oct 06 2002
next sibling parent "Rajiv Bhagwat" <dataflow vsnl.com> writes:
'main' is required to be treated by compilers as a special function (to not
break old code), and thus only for 'main' it is legal to declare it as
'void', declare it as int and not return a value. Remember, in older
versions of C, a function without type declaration was treated as returning
an int, and even then, it was ok for it to not return anything.

afunction(){
...
}

is in reality an 'int' function. These topics have been widely discussed in
C computer magazines and I recollect have been elucidated in the ARM
(Annotated Reference Manual), the standard which talks about C/C++.
- Rajiv


"bw" <bw_member pathlink.com> wrote in message
news:anpfnv$ikk$1 digitaldaemon.com...
 In article <anosh8$ke$1 digitaldaemon.com>, SD says...
Yes, I have the latest available.

 got version 8.29 ?


the 8.29 i have catches all those, don't understand why you're having

 /* testing for errors */
 #include <stdio.h>
 void main(void)
 {
 func();
 }
 int func()
 {

 }

 C:\cpp\my>sc -A -w- -r errs.c
 func();
 ^
 errs.c(8) : Error: function 'func' has no prototype
 errs.c(15) : Error: need at least one external def
 --- errorlevel 1

 C:\cpp\my>sc -A -w- -r -cpp errs.c
 func();
 ^
 errs.c(8) : Error: function 'func' has no prototype
 }
 ^
 errs.c(14) : Error: implied return of func at closing '}' does not return

 errs.c(15) : Error: need at least one external def
 --- errorlevel 1

Oct 07 2002
prev sibling parent SD <stephanedelaval wanadoo.fr> writes:
Hi
OK, that's fine now. I think the -cpp flag made the difference. Mny 
thanks
Stephane


bw <bw_member pathlink.com> wrote in
news:anpfnv$ikk$1 digitaldaemon.com: 

 In article <anosh8$ke$1 digitaldaemon.com>, SD says...
Yes, I have the latest available.

 got version 8.29 ?


the 8.29 i have catches all those, don't understand why you're having trouble? /* testing for errors */ #include <stdio.h> void main(void) { func(); } int func() { } C:\cpp\my>sc -A -w- -r errs.c func(); ^ errs.c(8) : Error: function 'func' has no prototype errs.c(15) : Error: need at least one external def --- errorlevel 1 C:\cpp\my>sc -A -w- -r -cpp errs.c func(); ^ errs.c(8) : Error: function 'func' has no prototype } ^ errs.c(14) : Error: implied return of func at closing '}' does not return value errs.c(15) : Error: need at least one external def --- errorlevel 1

Oct 08 2002