function placement / prototyping
Here is a really silly question im sure but its becomming confusing.
what is the ansi standard for function prototyping and placement. is it like this Code:
or like this Code:
Code:
|
The first case you presented is the one I generally see used, and makes the most sense. The allows you to move the function prototype (aka, function declaration) outside the source file into a header file to share the function with other programs. It is also the only version that doesn't cause warnings to be generated, IIRC. The second version is the WORST form of all, because it causes the compiler to "guess" about the definition for the function.
|
Cool thats what ive been doing is the first one.
i havent seen the second one anywhere however the reson for my question was really because of the first and thired ones. silly gnu programming tutorial it talkes about the ansi standard says the rest of the examples in that section are the ansi standard (with prototypes) . but then when you look at them there like the 3rd one not the first lol go figure :p |
I've seen the third method as a silly shortcut for throwaway programs (cases where it was developed for a single use). IMHO, it makes code readability and maintainability a bear. Also, what about the following case:
Code:
void handler1(void *x){ |
regarding topologically unsortable (i.e. cyclic) function prototype dependencies: why not use the fourth method?
Code:
void f1(void* x) { For reference, K&R do it in their book (2nd ed., at least). hth --Jonas |
I always hear people refer to K&R style, but I've always found it ugly. Aren't they the ones that reccomend:
Code:
void myfunc() I also think the "fourth style" above has one big flaw... it becomes a PAIN for mantainability. Every time you change f2(), you have to change that line in EACH function. |
Quote:
Code:
#define F2_PROTOTYPE void f2(void*) |
ok, fine. Is there any GOOD reason to do that?
|
Quote:
|
Quote:
|
Yes actually I have seen it in the form
Code:
but the original question was what is the ANSI standard way for best so called portablity. |
The variable NAME in the function declaration/prototype is optional. I usually include it as I try to make my names informative.
What do people usually find as style for documenting function prototypes? Put the comment above or below the prototype? That's always confused me. |
All times are GMT -5. The time now is 08:47 AM. |