order of declaration

Q

questions?

I have a file including all my function prototypes.
I include them at the most top of my program.
But some of the prototypes include the structures I declared later.

I didn't notice the problem at the beginning since compiler is not
complaining about this.
But I recently add another structure, it starts to complain. give me
warnings like declared in the parameter list

What's a good text to read about function prototypes?
 
F

Flash Gordon

questions? said:
thanks a lot

Please don't top post. Your reply belongs *under* the text you are
replying to, not above it. See
http://www.cpax.org.uk/prg/writings/topposting.php
EventHelix.com wrote:

EventHelix, please provide context, there is no guarantee that people
have, or ever will, see the article you are responding to. See
http://cfaj.freeshell.org/google/

I would also advice both of you to read
http://clc-wiki.net/wiki/Intro_to_clc

I would not rely on that site too much if I was you. I had only reached
the first line of the code when I saw a major error, using identifiers
reserved for the implementation name space.

There are some names beginning with an underscore you can use in certain
places, but the example on that site is not one of the situations where
you can use one.

The basic rule you should follow don't use *any* names starting with an
underscore. Learning what you can get away with is not worth the effort.

That site also does not answer the OPs original question.

It is legal to define a structure type in a parameter list, but not
tremendously useful. What you should do is define the struct type (but
not variables of that type, although you can declare variables as extern
in the header) in the header before your function declarations. e.g.

/* fred.h */
#ifndef FRED_H
#define FRED_H
/* Note I don't start the identifier with an underscore */

struct point {
int x;
int y;
};

int distance(struct point a, struct point b);

#endif
 
P

pete

questions? said:
I have a file including all my function prototypes.
I include them at the most top of my program.
But some of the prototypes include the structures I declared later.

I didn't notice the problem at the beginning since compiler is not
complaining about this.
But I recently add another structure, it starts to complain. give me
warnings like declared in the parameter list

What's a good text to read about function prototypes?

Place your type definitions before your prototypes in a c file.
 
M

Micah Cowan

pete said:
Place your type definitions before your prototypes in a c file.

If you're only using /pointers/ to those structures defined later, you
could simply declare them (without defining them) before the function
prototypes.

But there's no good reason I can think of not to put the whole
definition before the prototypes.

I should think that you (OP) would have come up with this answer on
your own...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top