Adi
Adi

Reputation: 731

Will declaring a function generate any issues in the code

In my project i have a Header file common.h which include many headers in it.Some of the files include Common.h and some other header which are already present in Common .h So In the Pre-Processing stage many functions get prototyped twice(Once from the Included header and other from Gui.h).I was wondering is this would cause any issue in long run.

Please suggest..Thanks in advance..

Upvotes: 0

Views: 86

Answers (2)

elimad
elimad

Reputation: 1152

As Chemistpp suggested,
#pragma once
is a good option to try, though it is non-standard.
Check out the advantages and disadvantages listed in the link.

Upvotes: 0

wholerabbit
wholerabbit

Reputation: 11546

Headers should have include guards so that they are only processed once:

#ifndef SOME_UNIQUE_STRING
#define SOME_UNIQUE_STRING

// Everything else here

#endif

By "Everything" I mean "everything", starting with your #includes if any.

SOME_UNIQUE_STRING could be the name of the module as long as it is unlikely to coincide with another define somewhere else.

If you look in your library headers, you will notice they use include guards like this.

Upvotes: 4

Related Questions