473,835 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preprocessor, nested files etc.

Hi,

I'm hoping that someone can point me into the right direction here. I'm
trying to gain a bit of a better understanding on how the preprocessor
works - something that seems like a simple topic! I just keep running into
problems (Windows platform) because files are included in the wrong order,
one include file messes up the other one etc.. I think I need to brush up on
some basics here.

In this example project, I have several cpp files (~10) that all pretty much
include one common header file. In Visual Studio I turned the option on to
actually generate those pre-processed files - so that I could see what's
actually going on behind the scenes.

Well, I expected one big file but instead got one preprocessor file for each
of the cpp files in the project. OK, I suppose that this makes sense. One of
the things however I'm constantly trying to do is to prevent header files
from being included more than once - do I not need to worry about this when
it's included from different cpp files?

Also, when I #define macros and put them at the beginning of the header file
like

#ifndef HEADERFILE1_H
#define HEADERFILE1_H

....
...
#endif

then those macro definitions don't seem to stick. When the next cpp files is
being processed, the header file is being included again - even though the
macro was previously defined

Is this normal, and where am I getting confused?
Thanks!
Flo.
Jul 22 '05
12 1584

"Florian" <wi*******@gmxR EMOVEUPPERCASE. net> wrote in message
news:3l******** *******@newssvr 28.news.prodigy .com...
Thanks Ali,

That makes more sense now. I didn't know that in CPP each file was it's own translation unit. I suppose that's not the case in C then, correct?


Not correct. C and C++ have the same compilation model.

john
Jul 22 '05 #11


Florian wrote:
Thanks Ali,

That makes more sense now. I didn't know that in CPP each file was it's own
translation unit. I suppose that's not the case in C then, correct?


C source files are complied the same as C++. Each is its own translation
unit.

Jul 22 '05 #12
Florian wrote:

Thanks Ali,

That makes more sense now. I didn't know that in CPP each file was it's own
translation unit. I suppose that's not the case in C then, correct?


Same thing

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #13

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

Similar topics

8
5717
by: Bram Stolk | last post by:
Hi there, What could I use to parse CPP macros in Python? I tried the Parnassus Vaults, and python lib docs, but could not find a suitable module. Thanks, Bram
24
40320
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was looking to write something along the lines of:
13
3596
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the amount of preprocessor directives used in these code. Can anyone please tell me how to actually use these preprocessor directives in a more professional way like selecting particular lines of code suited for some particular hardware etc...
9
3663
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour. Could someone point me to the appropriate section, or else confirm the behaviour as a bug? For a particular project, I am using the C preprocessor phase only. I am not using the standalone program 'cpp' because proper functioning of my project...
2
6652
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0 where the definitions were: _UNICODE,_DEBUG,_WIN32_DCOM,WIN32,_WINDOWS,_WINDLL,_AFXDLL,_USRDLL In VC++7.1, these are the preprocessor definitions of the project (right-click the project in Solution Explorer and choose Properties -> C++ ->...
2
1626
by: Prashant Mahajan | last post by:
I just wanted comments from you all on the following topic: Let's say we have 2, C code files namely file1.c and file2.c. file1.c contains few pre-processor definations say #define TEST1 10 We now compile file1.c , make it's object file. and use this object file in the other file i.e file2.c. Then can we use the macro TEST1 in file2.c as well. As I understand about macros, they are replaced by their corresponding values , but are the...
32
2811
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
21
7654
by: Bogdan | last post by:
Can anyone recommend a program for indentation of C preprocessor directives. My file looks like this: #ifdef a #define b #else #define c #endif int main() {
13
464
by: josh | last post by:
Hi, I've read that in the future the C++ will not more support the preprocessor and now some preprocessor functionality have already been implemented in the language itself. What are that? Thanks.
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10815
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...
0
10526
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7770
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
6970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4435
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
2
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.