In C, should I define (not declare/prototype) a function that takes no arguments with void or with an empty list? -


there may or may not duplicate question, although tried find 1 everyone's answer seemed referring declaration/prototype. specify definition void foo() { } same void foo(void) { }, way should use? in c89? in c99? believe should start using void foo(void); prototype declarations, there difference @ if use void or not definition?

i'll try answer , practically.
practice , reference i'm familiar with, c89 , c99 should treat declaration/definition/call of functions which take no arguments , return no value equally. in case 1 omits prototype declaration (usually in header file), definition has specify number , type of arguments taken (i.e. must take form of prototype, explicitly void foo(void) taking no arguments) , should precede actual function call in source file (if used in same program). i've been advised write prototypes , decently segmented code part of programming practice.

declaration:

void foo (void); /*not void foo(), in order conform prototype definition !*/ 

definition:

void foo (void) /*must match prototype declaration !*/ {   /*code function does*/   return; } 

function call within main() or function:

...   foo(); ... 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -