Re: [Warzone-dev] [Warzone-commits] r1305 - in /trunk/lib: netplay/netplay.c sound/cdaudio.c
Stefan Huehner schreef: > On Sun, May 20, 2007 at 04:01:27PM +0200, Giel van Schijndel wrote: > >> Stefan Huehner schreef: >> >>> Author: shuehner >>> Date: Sun May 20 15:51:53 2007 >>> New Revision: 1305 >>> >>> URL: http://svn.gna.org/viewcvs/warzone?rev=1305&view=rev >>> Log: >>> 2 small fixes in function declarations : () -> (void) >>> >>> Modified: >>> trunk/lib/netplay/netplay.c >>> trunk/lib/sound/cdaudio.c >>> >> According to the ISO C standard (both C89 and C99) this is _not_ >> necessary. The only place where you need to use a function signature of >> `(void)`, to indicate a function taking no arguments, is in forward >> declarations, not in function definitions. >> > > Hmm i haven't got the text here to look it up myself. But chaning i.e. > the static function declaration in cdaudio.c:58 to (void) removes the > following to warning from my gcc warning output: > > -cdaudio.c:58: warning: function declaration isn't prototype > -cdaudio.c: In function: 'ProcessedBuffers': > -cdaudio.c:58: warning: old-style function definition > > I'am compiling with additional -Wstrict-prototypes abd > -Wold-style-definition to catch these. > > And for a direct improvement which comes in changing these i attach the > following 2 test-cases. > > test1.c has the following 'static void test1()' and if you compile this > you'll notive that the compiler doesn't catch the function call in main > with an argument. I assume that i wanted to have the test1 function > without arguments. > > test2.c is the same programs but with 'static void test1(void)'. Now the > compiler correctly catches the wrong function call. > Yes, those are results you can expect when functions don't have forward declarations, as is usual with static functions. So in the case of static functions declaring an argument list of `(void)` is correct. In case of non-static functions however (i.e. with external linkage) you _do_ need a forward declaration. So in that case it is better to keep the argument list of `(void)` in the function declaration and out of its definition. -- Giel signature.asc Description: OpenPGP digital signature ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] [Warzone-commits] r1305 - in /trunk/lib: netplay/netplay.c sound/cdaudio.c
On Sun, May 20, 2007 at 04:01:27PM +0200, Giel van Schijndel wrote: > Stefan Huehner schreef: > > Author: shuehner > > Date: Sun May 20 15:51:53 2007 > > New Revision: 1305 > > > > URL: http://svn.gna.org/viewcvs/warzone?rev=1305&view=rev > > Log: > > 2 small fixes in function declarations : () -> (void) > > > > Modified: > > trunk/lib/netplay/netplay.c > > trunk/lib/sound/cdaudio.c > > > According to the ISO C standard (both C89 and C99) this is _not_ > necessary. The only place where you need to use a function signature of > `(void)`, to indicate a function taking no arguments, is in forward > declarations, not in function definitions. Hmm i haven't got the text here to look it up myself. But chaning i.e. the static function declaration in cdaudio.c:58 to (void) removes the following to warning from my gcc warning output: -cdaudio.c:58: warning: function declaration isn't prototype -cdaudio.c: In function: 'ProcessedBuffers': -cdaudio.c:58: warning: old-style function definition I'am compiling with additional -Wstrict-prototypes abd -Wold-style-definition to catch these. And for a direct improvement which comes in changing these i attach the following 2 test-cases. test1.c has the following 'static void test1()' and if you compile this you'll notive that the compiler doesn't catch the function call in main with an argument. I assume that i wanted to have the test1 function without arguments. test2.c is the same programs but with 'static void test1(void)'. Now the compiler correctly catches the wrong function call. Regards, Stefan static void test1() { } int main(int argc, char *argv[]) { test1(5); return 0; } static void test1(void) { } int main(int argc, char *argv[]) { test1(5); return 0; } ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] [Warzone-commits] r1305 - in /trunk/lib: netplay/netplay.c sound/cdaudio.c
Stefan Huehner schreef: > Author: shuehner > Date: Sun May 20 15:51:53 2007 > New Revision: 1305 > > URL: http://svn.gna.org/viewcvs/warzone?rev=1305&view=rev > Log: > 2 small fixes in function declarations : () -> (void) > > Modified: > trunk/lib/netplay/netplay.c > trunk/lib/sound/cdaudio.c > According to the ISO C standard (both C89 and C99) this is _not_ necessary. The only place where you need to use a function signature of `(void)`, to indicate a function taking no arguments, is in forward declarations, not in function definitions. -- Giel signature.asc Description: OpenPGP digital signature ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev