473,695 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ coding standarts and how to structure "bigger" projects

Hi there
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.

I have some generel experiense in programming but I lack many things
specific to C++.
One thing that causes me many troubles is how to properly nest "#include
'filename'" statements in combination with the "#pragma once" directive and
"using namespace".

I have one specific project containing ~15 header files and as many saource
files which gives me trouble when the compiler starts linking.
"unresolved externals" showing all the time. Compiling each file on it's own
does not show any errors.

Each file has it's own class, and pointers to some of the classes are given
to them so they can use each other (one file combines it all and creates
objects and pointers to them).
I know these problems occour because my understanding of how to structure
bigger (well for me this is "bigger" than I'm used to) projects are
insufficient.
I have not been able to find any usefull information regarding this topic
though I've been searching google all day.

This project are made in VC++ 7 but as far as I'm concerned the compiler
should not matter at all as long as I'm using the right coding standarts.
I might add that the project would previously compile just fine using GCC
but then terminate upon execution when one class member tries to access
public data in another class through it's pointer.

This shows me I need some general knowledge about projects with multiple
files that include each other.

I hope some of you can point me in direction towards the shining bright
light:)
- Mikkel
Jul 22 '05 #1
4 3076
"Mikkel christensen" <04***@eit.iha. dk> wrote...
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.
[...]
This shows me I need some general knowledge about projects with multiple
files that include each other.

I hope some of you can point me in direction towards the shining bright
light:)


I'd probably start with microsoft.publi c.vc.project_mg t newsgroup.

There are good books on VC++ as well (alas, I don't remember the titles,
the same newsgroup or m.p.vc.language should help you with that)

V
Jul 22 '05 #2

"Mikkel christensen" <04***@eit.iha. dk> wrote in message
news:cm******** **@news.cyberci ty.dk...
Hi there
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.

I have some generel experiense in programming but I lack many things
specific to C++.
One thing that causes me many troubles is how to properly nest "#include
'filename'" statements in combination with the "#pragma once" directive
and
"using namespace".

I have one specific project containing ~15 header files and as many
saource
files which gives me trouble when the compiler starts linking.
"unresolved externals" showing all the time. Compiling each file on it's
own
does not show any errors.

Each file has it's own class, and pointers to some of the classes are
given
to them so they can use each other (one file combines it all and creates
objects and pointers to them).
I know these problems occour because my understanding of how to structure
bigger (well for me this is "bigger" than I'm used to) projects are
insufficient.


This is too big a topic to reply to in a newsgroup post.

Do you know what should go into a header file and what shouldn't? Do you
know the difference between a declaration and a definition (this seems to be
the commonest mistake). Do you know never to include one source file inside
another? Do you know that each header file should include the other header
files it needs to compile if it is the first header file included in a
source file? Do you know how to use include guards? Apparently not since you
are using the non-standard #pragma once, you should use include guards
instead. Do you know never to use 'using namespace' inside a header file?
Could you post a sample header file from your code. It would really help to
have some specifics to work on.

If any of the above seems interesting or surprising then respond and I'll
try an focus in on the specific areas you are having problems with.

And post some code!!!

john
Jul 22 '05 #3
Just to comment on a few of your problems...

<You wrote..
I have one specific project containing ~15 header files and as many saource
files which gives me trouble when the compiler starts linking.
"unresolved externals" showing all the time. Compiling each file on it's
own
does not show any errors.
And the reasons you can compile each file by itself, is that you do not
link...
The linker is the one complaining about "Unresolved externals" or
"unresolved symbols"...
My guess is, there is some kind og namespace conflict... One difference
between compilers I could think of is,
wether or not they what all members defined, even if they are not used in
the application. I think VC7.net wants
them defined, do not know about gcc though... (and I do not know if the
standard has anything on this)

With namespaces, be sure to structure your files so all #includes are
outside namespaces...
header file: "SomeCollection OfSomeSort.h"
#pragma once

#include "MySpecial. h"

namespace Flanhart {
class SomeCollectionO fSomeSort {
public:
SomeCollectionO fSomeSort();
};

}//end namespace Flanhart

implementation file:"SomeColle ctionOfSomeSort .cpp"

//include here - first the file you are implementing
#include "SomeCollection OfSomeSort.h"

//include dependencies here

namespace Flanhart {
//implement here
SomeCollectionO fSomeSort::Some CollectionOfSom eSort() {
//DoStuff
}

}//end namespace Flanhart
So do not try to #include anything while you are in a namespace, since the
header file itself states it is in a namespace.. If you cannot figure it
out, try removing all namespaces, and check if you can build, if you cannot,
then it is not a namespaces, but probably access to libraries or access to
your own unimplemented functions/methods/(statics)...

Hope this will help you

Jesper Madsen

"Mikkel christensen" <04***@eit.iha. dk> wrote in message
news:cm******** **@news.cyberci ty.dk...
Hi there
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.

I have some generel experiense in programming but I lack many things
specific to C++.
One thing that causes me many troubles is how to properly nest "#include
'filename'" statements in combination with the "#pragma once" directive and "using namespace".

I have one specific project containing ~15 header files and as many saource files which gives me trouble when the compiler starts linking.
"unresolved externals" showing all the time. Compiling each file on it's own does not show any errors.

Each file has it's own class, and pointers to some of the classes are given to them so they can use each other (one file combines it all and creates
objects and pointers to them).
I know these problems occour because my understanding of how to structure
bigger (well for me this is "bigger" than I'm used to) projects are
insufficient.
I have not been able to find any usefull information regarding this topic
though I've been searching google all day.

This project are made in VC++ 7 but as far as I'm concerned the compiler
should not matter at all as long as I'm using the right coding standarts.
I might add that the project would previously compile just fine using GCC
but then terminate upon execution when one class member tries to access
public data in another class through it's pointer.

This shows me I need some general knowledge about projects with multiple
files that include each other.

I hope some of you can point me in direction towards the shining bright
light:)
- Mikkel

Jul 22 '05 #4
Mikkel christensen wrote:
I wonder if any of you could point me in a direction where I can find some
usefull information about coding standarts.
I have yet to see one single coding standard document that I agree with
(now) - even ones I wrote myself.

Project requirements change, tools change (and get better).

For example, at one point, my coding standard was to not use namespaces.
(because at the time the compilers and debuggers did not support them
well, this is no longer the case).

Exceptions are still in my grey area. Having used them in a recent
project, I found them both useful and generally more difficult to debug
in some cases.

The things that remain in my (unwritten) coding standard are benign
things like indentation etc. The rest are based on requrements of the
project.

Much of it is driven by a "Test Driven Design" (aka TDD) process where
the final design deliverables are interfaces and unit tests and peer
review is done on the unit tests themselves.

I have some generel experiense in programming but I lack many things
specific to C++.
One thing that causes me many troubles is how to properly nest "#include
'filename'" statements in combination with the "#pragma once" directive and
"using namespace".
The most portable thing is to use guards, e.g.

----- file.h -----

#ifndef x__file_h__x
#define x__file_h__x 1

.... stuff goes here ...

#endif // x__file_h__x

------------------

If you look at austria C++ you'll see what I mean.
http://austria.sourceforge.net/dox/h...8h-source.html

I have one specific project containing ~15 header files and as many saource
files which gives me trouble when the compiler starts linking.
"unresolved externals" showing all the time. Compiling each file on it's own
does not show any errors.
Are you targetting more than MS ? If so you might want to look at a
cross platform build system.

Each file has it's own class, and pointers to some of the classes are given
to them so they can use each other (one file combines it all and creates
objects and pointers to them).
I'm not understanding what you want to say.
I know these problems occour because my understanding of how to structure
bigger (well for me this is "bigger" than I'm used to) projects are
insufficient.
I have not been able to find any usefull information regarding this topic
though I've been searching google all day.

This project are made in VC++ 7 but as far as I'm concerned the compiler
should not matter at all as long as I'm using the right coding standarts.
I might add that the project would previously compile just fine using GCC
but then terminate upon execution when one class member tries to access
public data in another class through it's pointer.

This shows me I need some general knowledge about projects with multiple
files that include each other.

I hope some of you can point me in direction towards the shining bright
light:)


Take a look at how Austria C++ is organized - It uses MakeXS as it's
build tool which can be made to generate VC++ project files as well as
build on platforms that use GNU make. It works with cygwin under Win32.

Jul 22 '05 #5

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

Similar topics

23
3401
by: assaf__ | last post by:
Hello, I am beginning to work on a fairly large project and I'm considering to use python for most of the coding, but I need to make sure first that it is reliable enough. I need to make sure that I won't have surprises when my program runs on different real-world systems. So far I wrote a little script with python using urllib, and on one computer it failed completely because of a problem in getting the proxies (in my opinion this is a...
36
6382
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
14
1753
by: Jason Heyes | last post by:
I have read item 26 of "Exceptional C++" that explains a way of minimising compile-time dependencies and, therefore, a way to improve compile speeds. The procedure involves replacing #include directives with forward declarations from within header files. However, a potentially large number of source files may have previously relied on the removed #include directives being present. Therefore it is likely that a large number of source...
18
4359
by: aum | last post by:
Hi all, I've been doing a fair bit of python gui programming on and off, jumping between different widget sets along the way, from anygui, to pythoncard, to tkinter/PMW, then to wxPython/wxGlade, and have now settled on a python gui API that seems to get barely a mention - PyFLTK. PyFLTK (http://pyfltk.sourceforge.net) is a SWIG-generated Python wrapper around the multiplatform FLTK widget set ('Fast Light Tool Kit' -...
8
1837
by: Maxi | last post by:
Hello, i'm sorry my bad english :( I have CR9 Webservice, how to change databadse name and User_name into Webservice method? (not Viewer Control) Tks!! -- --------------------------
169
9071
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
3
3922
by: | last post by:
I'm seeking (probably basic) guidance on the right way to split a large site that's supposed to represent one domain(mydomain.org) into many small VS.NET projects, and how to avoid issues with multiple web.config files leading to the error: "It is an error to use a section registered as allowDefinition = 'MachineToApplication'"... I'm fairly new to VS.NET and my sloppy first solution was to make one huge solution/project with just one...
27
4202
by: duli | last post by:
Hi: I would like recommendations for books (in any language, not necessarily C++, C, python) which have walkthroughs for developing a big software project ? So starting from inception, problem definition, design, coding and final delivery on a single theme or application. Most of the code I have written and books that I have read deal with toy programs and I am looking for something a bit more comprehensive. For example, maybe a...
6
1697
by: Cirene | last post by:
Do you prefer writing your DAL code by hand, or do you like to use the graphical interface of creating XSD datasets in Visual Studio 2008? What do you feel are the pros/cons? I hope this makes sense...
0
8587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9140
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8867
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8841
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7688
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6511
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4599
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.