473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

order of declaration

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?

Mar 21 '06 #1
7 3024
I would recommend splitting header files. Use forward declarations for
the structures to decouple the structures from the function prototypes.

The following article might help:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

The article is about C++ header file inclusion. However the same
principles apply to C.

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based Real-time and Embedded System Design Tool

Mar 21 '06 #2
thanks a lot

EventHelix.com wrote:
I would recommend splitting header files. Use forward declarations for
the structures to decouple the structures from the function prototypes.

The following article might help:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

The article is about C++ header file inclusion. However the same
principles apply to C.

--
EventStudio System Designer 2.5 - http://www.EventHelix.com/EventStudio
Sequence Diagram Based Real-time and Embedded System Design Tool


Mar 21 '06 #3
questions? wrote:
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 recommend splitting header files. Use forward declarations for
the structures to decouple the structures from the function prototypes.

The following article might help:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

The article is about C++ header file inclusion. However the same
principles apply to C.


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
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Mar 21 '06 #4
questions? wrote:

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.

--
pete
Mar 23 '06 #5
On Thu, 23 Mar 2006 22:16:24 GMT, pete <pf*****@mindspring.com> wrote:
questions? wrote:

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.


Better in an h file.
Remove del for email
Mar 24 '06 #6
Barry Schwarz wrote:

On Thu, 23 Mar 2006 22:16:24 GMT, pete <pf*****@mindspring.com> wrote:
questions? wrote:

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.


Better in an h file.


Place your type definitions before your prototypes
in a translation unit.

--
pete
Mar 24 '06 #7
pete <pf*****@mindspring.com> writes:
questions? wrote:

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.


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...
Mar 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
10
by: Chris Gordon-Smith | last post by:
I am currently revisiting the code of a C++ application and restructuring the code where appropriate to make it consistent with the overall logical design. As part of this, I am looking at the...
7
by: Dave | last post by:
#include <iostream> using namespace std; struct foo { int a; int b; };
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
3
by: Henning Hasemann | last post by:
Hi all, On larger projects I used the following 'technique' (well in fact its a really simple thing): 1. Write one source-code file for each 'large' class and one corresponding header file....
0
by: todd.freed | last post by:
Hello. I'll make this quick - its quite a conundrum I have the following markup <MyNS:MyControl runat="server" id="myId" CustomProperty1="value" CustomProperty1="value"...
5
by: Gary Wessle | last post by:
Hi I read some where about the order variables are declared in a class may help space optimization. find the size of bits a variable takes and declare them from biggest to the lowest. so in my...
2
by: Dennis Jones | last post by:
Hello, I have a class that will eventually look something like this: class TTableHolder { private: boost::scoped_ptr<TSessionFSession; boost::shared_ptr<TTableFTable;
7
by: Peter | last post by:
I know the order of construction of member and base class objects. My question is the following: Is the order of evaluation of argument lists for these constructors also defined? E.g. can I...
8
by: Jess | last post by:
Hello, When I define default constructors, I tend to use constructor initializers for member data. However, I was told the order in which members are initialized is determined by the order of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.