I have a class which only purpose is to provide services to a variety
of classes in other files. The 'manipulator' class is aware of the
other classes only because the header files have been include in its
header file. However, there are times when some of the other classes
are not and will not be dealt with, thus the need to include the header
files does not arrive. To handle this, I have used compiler
preprocessors to prevent the unneeded header files and method
declarations / implementations to be compiled, here is an example:
--- popeye.hpp ---
#ifndef POPEYE_HPP
#define POPEYE_HPP
class popeye{ /*the whole enchilada goes here */};
--- mikey.hpp ---
#ifndef MIKEYMOUSE_HPP
#define MIKEYMOUSE_HPP
class mikey{ /*more cheese senior?*/ };
--- donal.hpp ---
#ifndef DONALDUCK_HPP
#define DONALDUCK_HPP
class duck{ /* para bailar la banba */};
--- manipulator.hpp ---
#ifndef MANIPULATOR_HPP
#define MANIPULATOR_HPP
#ifdef POPEYE_HPP
#include "popeye.hpp "
#endif
#ifdef MIKEYMOUSE_HPP
#include "mikey.hpp"
#endif
#ifdef DONALDUCK_HPP
#include "donal.hpp"
#endif
class manipulator{
private:
..........
protected:
..........
public:
..........
#ifdef POPEYE_HPP
void handle_popeye(c onst popeye&);
#endif
#ifdef MIKEMOUSE_HPP
void handle_mikey(co nst mikey&);
#endif
#ifdef DONALDUCK_HPP
void handle_duck(con st duck&);
#endif
.........
};
#ifdef POPEYE_HPP
void manipulator::ha ndle_popeye(con st popeye& p){/*...*/}
#endif
#ifdef MIKEMOUSE_HPP
void manipulator::ha ndle_mikey(cons t mikey& p){/*...*/}
#endif
#ifdef DONALDUCK_HPP
void manipulator::ha ndle_duck(const duck& p){/*...*/}
#endif
--- main.cpp --
#include "popeye.hpp "
#include "manipulato r"
int main(){
popeye p;
manipulator m;
m.handle_popeye (p); //<<== Segmentation Fault
return 0;
}
My question is: why is it that if I remove the conditional
preprocessors I don't get a segmentation fault?
T. I. A. F.
(Thank In Advance Folks) 6 1604
Al-Burak schrieb: I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the unneeded header files and method declarations / implementations to be compiled, here is an example:
Really ugly design...
Didn't you know that the preprocessor is the root of all evil?
--- popeye.hpp --- #ifndef POPEYE_HPP #define POPEYE_HPP class popeye{ /*the whole enchilada goes here */};
<snip> --- manipulator.hpp --- #ifndef MANIPULATOR_HPP #define MANIPULATOR_HPP #ifdef POPEYE_HPP #include "popeye.hpp "
This has no effect. Do you understand the inclusion guards?
#endif
<snip> class manipulator{ private: .......... protected: .......... public: .......... #ifdef POPEYE_HPP void handle_popeye(c onst popeye&); #endif
<snip> --- main.cpp -- #include "popeye.hpp " #include "manipulato r"
int main(){ popeye p; manipulator m; m.handle_popeye (p); //<<== Segmentation Fault return 0; }
My question is: why is it that if I remove the conditional preprocessors I don't get a segmentation fault?
Why do you expect segmentation faults? There is nothing that causes one.
You could only run into compilation errors.
What conditionals did you remove exactly?
Thomas
Al-Burak wrote: I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the unneeded header files and method declarations / implementations to be compiled, here is an example:
--- popeye.hpp --- #ifndef POPEYE_HPP #define POPEYE_HPP class popeye{ /*the whole enchilada goes here */};
--- mikey.hpp --- #ifndef MIKEYMOUSE_HPP #define MIKEYMOUSE_HPP class mikey{ /*more cheese senior?*/ };
--- donal.hpp --- #ifndef DONALDUCK_HPP #define DONALDUCK_HPP class duck{ /* para bailar la banba */};
--- manipulator.hpp --- #ifndef MANIPULATOR_HPP #define MANIPULATOR_HPP #ifdef POPEYE_HPP #include "popeye.hpp " #endif #ifdef MIKEYMOUSE_HPP #include "mikey.hpp" #endif
#ifdef DONALDUCK_HPP #include "donal.hpp" #endif
class manipulator{ private: .......... protected: .......... public: .......... #ifdef POPEYE_HPP void handle_popeye(c onst popeye&); #endif
#ifdef MIKEMOUSE_HPP void handle_mikey(co nst mikey&); #endif
#ifdef DONALDUCK_HPP void handle_duck(con st duck&); #endif ......... };
<snip>
I don't really understand what you are trying to do. Your manipulator
class may handle popeye() objects and uses the preprocessor to
specify this. Your manipulator class potentially can handle many
classes. What exactly does manipulator do? Can't the popeye
specific stuff be moved back into the popeye class? There's gotta be
a way to do this that doesn't involve the preprocessor!
Coulr be have a more specific example?
--
Nick Keighley
"Al-Burak" <ja******@netsc ape.net> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. . I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the unneeded header files and method declarations / implementations to be compiled, here is an example:
--- popeye.hpp --- #ifndef POPEYE_HPP #define POPEYE_HPP class popeye{ /*the whole enchilada goes here */};
--- mikey.hpp --- #ifndef MIKEYMOUSE_HPP #define MIKEYMOUSE_HPP class mikey{ /*more cheese senior?*/ };
--- donal.hpp --- #ifndef DONALDUCK_HPP #define DONALDUCK_HPP class duck{ /* para bailar la banba */};
--- manipulator.hpp --- #ifndef MANIPULATOR_HPP #define MANIPULATOR_HPP #ifdef POPEYE_HPP #include "popeye.hpp " #endif
This isn't going to work. POPEYE_HPP is defined *inside* popeye.hpp. But
you're only including popeye.hpp if it's already defined. If it was already
defined the header would already have been included anyway so no use to
include here again.
That's kinda like saying, "If this sealed black box contains the number 42
open it. Other wise don't open it." You don't know what's inside the box
until you open it.
#ifdef MIKEYMOUSE_HPP #include "mikey.hpp" #endif
#ifdef DONALDUCK_HPP #include "donal.hpp" #endif
class manipulator{ private: .......... protected: .......... public: .......... #ifdef POPEYE_HPP void handle_popeye(c onst popeye&); #endif
#ifdef MIKEMOUSE_HPP void handle_mikey(co nst mikey&); #endif
#ifdef DONALDUCK_HPP void handle_duck(con st duck&); #endif ......... }; #ifdef POPEYE_HPP void manipulator::ha ndle_popeye(con st popeye& p){/*...*/} #endif #ifdef MIKEMOUSE_HPP void manipulator::ha ndle_mikey(cons t mikey& p){/*...*/} #endif #ifdef DONALDUCK_HPP void manipulator::ha ndle_duck(const duck& p){/*...*/} #endif
Extemely ugly code and prone to maintainence nightmares. I would find some
other way to do this.
--- main.cpp -- #include "popeye.hpp " #include "manipulato r"
int main(){ popeye p; manipulator m; m.handle_popeye (p); //<<== Segmentation Fault return 0; }
My question is: why is it that if I remove the conditional preprocessors I don't get a segmentation fault?
T. I. A. F. (Thank In Advance Folks)
Thanks for your prompt response Jim.
When main.cpp is compiled, popeye.hpp is included. popeye.hpp in turn
defines a variable named POPEYE_HPP.
Later the compiler finds the inclusion of 'manipulator.hp p' where the
a few questions are posted to the compiler:
Does the variable POPEYE_HPP exist?
If the variable exist, include the file popeye.hpp.
Otherwise the file is ignored.
After this question has been answered, the compiler is asked again if
the the variable POPEYE_HPP has been declared, if so, it compiles the
function declaration 'handle_popeye( )', or ignore it otherwise.
Finally, in the 'manipulator.cp p' the same question is asked before
compiling the implementation of the function 'handle_popeye( )'.
Then program returns to main and should process 'm.handle_popey e()'
without any problems; because, since the compiler *did find the
variable POPEYE_HPP, the method 'manipulator::h andle_popeye() *was
compiled.
Now, this is how I undertand it. Am I right?
Thanks Jim
Jim Langston wrote: "Al-Burak" <ja******@netsc ape.net> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. .I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been include in its header file. However, there are times when some of the other classes are not and will not be dealt with, thus the need to include the header files does not arrive. To handle this, I have used compiler preprocessors to prevent the unneeded header files and method declarations / implementations to be compiled, here is an example:
--- popeye.hpp --- #ifndef POPEYE_HPP #define POPEYE_HPP class popeye{ /*the whole enchilada goes here */};
--- mikey.hpp --- #ifndef MIKEYMOUSE_HPP #define MIKEYMOUSE_HPP class mikey{ /*more cheese senior?*/ };
--- donal.hpp --- #ifndef DONALDUCK_HPP #define DONALDUCK_HPP class duck{ /* para bailar la banba */};
--- manipulator.hpp --- #ifndef MANIPULATOR_HPP #define MANIPULATOR_HPP #ifdef POPEYE_HPP #include "popeye.hpp " #endif
This isn't going to work. POPEYE_HPP is defined *inside* popeye.hpp. But you're only including popeye.hpp if it's already defined. If it was already defined the header would already have been included anyway so no use to include here again.
That's kinda like saying, "If this sealed black box contains the number 42 open it. Other wise don't open it." You don't know what's inside the box until you open it.
#ifdef MIKEYMOUSE_HPP #include "mikey.hpp" #endif
#ifdef DONALDUCK_HPP #include "donal.hpp" #endif
class manipulator{ private: .......... protected: .......... public: .......... #ifdef POPEYE_HPP void handle_popeye(c onst popeye&); #endif
#ifdef MIKEMOUSE_HPP void handle_mikey(co nst mikey&); #endif
#ifdef DONALDUCK_HPP void handle_duck(con st duck&); #endif ......... }; #ifdef POPEYE_HPP void manipulator::ha ndle_popeye(con st popeye& p){/*...*/} #endif #ifdef MIKEMOUSE_HPP void manipulator::ha ndle_mikey(cons t mikey& p){/*...*/} #endif #ifdef DONALDUCK_HPP void manipulator::ha ndle_duck(const duck& p){/*...*/} #endif
Extemely ugly code and prone to maintainence nightmares. I would find some other way to do this.
--- main.cpp -- #include "popeye.hpp " #include "manipulato r"
int main(){ popeye p; manipulator m; m.handle_popeye (p); //<<== Segmentation Fault return 0; }
My question is: why is it that if I remove the conditional preprocessors I don't get a segmentation fault?
T. I. A. F. (Thank In Advance Folks)
Please don't top-post. Put your reply below or in-line, not above.
Rearranged. Thank you.
Al-Burak wrote: Jim Langston wrote: "Al-Burak" <ja******@netsc ape.net> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. . --- popeye.hpp --- #ifndef POPEYE_HPP #define POPEYE_HPP class popeye{ /*the whole enchilada goes here */};
--- manipulator.hpp --- #ifndef MANIPULATOR_HPP #define MANIPULATOR_HPP #ifdef POPEYE_HPP #include "popeye.hpp " #endif This isn't going to work. POPEYE_HPP is defined *inside* popeye.hpp. But you're only including popeye.hpp if it's already defined. If it was already defined the header would already have been included anyway so no use to include here again.
That's kinda like saying, "If this sealed black box contains the number 42 open it. Other wise don't open it." You don't know what's inside the box until you open it.
class manipulator{ private: .......... protected: .......... public: .......... #ifdef POPEYE_HPP void handle_popeye(c onst popeye&); #endif
}; #ifdef POPEYE_HPP void manipulator::ha ndle_popeye(con st popeye& p){/*...*/} #endif
Extemely ugly code and prone to maintainence nightmares. I would find some other way to do this.
--- main.cpp -- #include "popeye.hpp " #include "manipulato r"
You have structured your code so that if you include these two the
other way round (manipulator first) you don't get the effect you want.
Every header file should be entirely self-contained. It should not be a
requirement to include other things first, in the right order, to get
them working. Otherwise, you can guarantee one day that you will get it
wrong and your program will not work.
int main(){ popeye p; manipulator m; m.handle_popeye (p); //<<== Segmentation Fault return 0; }
My question is: why is it that if I remove the conditional preprocessors I don't get a segmentation fault? Thanks for your prompt response Jim. When main.cpp is compiled, popeye.hpp is included. popeye.hpp in turn defines a variable named POPEYE_HPP. Later the compiler finds the inclusion of 'manipulator.hp p' where the a few questions are posted to the compiler: Does the variable POPEYE_HPP exist? If the variable exist, include the file popeye.hpp. Otherwise the file is ignored.
This dependency on order of including the header files is your
maintenance nightmare.
After this question has been answered, the compiler is asked again if the the variable POPEYE_HPP has been declared, if so, it compiles the function declaration 'handle_popeye( )', or ignore it otherwise.
Finally, in the 'manipulator.cp p' the same question is asked before compiling the implementation of the function 'handle_popeye( )'.
And does manipulator.cpp include (directly or indirectly) popeye.h?
Preprocessor symbols are not remembered between different source files.
If main.cpp includes popeye.h then main.cpp is compiled with POPEYE_HPP
defined. If manipulator.cpp does not include popeye.h then
manipulator.cpp is compiled *without* POPEYE_HPP defined, regardless of
whether it was defined when compiling main.cpp.
Gavin Deane
Oooohh!
Gee, man!
Live and learn!
Thanks Gavin, thanks so much. I was really messed up on this one.
Have a good one, but if you are having more than one... call me! ;) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: p s |
last post by:
hi
can someone tell me how to ensure the height of my window is always exact?
(excluding titlebar) in VB6
e.g. if i set the form to 300 pixels, then the total height of the form
takes into account the title bar, however i want to use a specific
background graphic in the main form background.... visual styles, and themes
and so on make this...
|
by: kmunderwood |
last post by:
I am having trouble excluding select xml out to HTML using xsl
I want to ignore some xml and turn others red
I can not find the right way to both:
1. Only show the <tag> that want to, and
2. Turn an attribute a color when it falls below a certain level.
|
by: Boris |
last post by:
Hi, folks!
I need to solve next problem.
In my project there is a refernce on external Oracle's dll. Usualy I need it
for regular work. But for debuging of the project I can use simulator, i.e.
instead of using Oracle for some connectivity I can pick up file from disk
that simulates Oracle's output. When I use simulator I would like to not...
|
by: Jon Maz |
last post by:
Hi,
Curiosity - when you right-click on a file in the VS.Net Solution Explorer
and select "Exclude from Project", it continues to be shown in the Solution
Explorer as a sort of ghostly outline (as long as you have selected "Show
All Files"). Yet if you open up the project file (which is just XML) in a
text editor, the reference to the...
|
by: Olav Tollefsen |
last post by:
I'm creating an ASP.NET e-commerce web site and I have to conditionally
(depending on site / user settings) display prices either excluding or
including tax. Prices are typically read from a database (where also the tax
rates are stored) various places in the code and typically (but now always)
the values are returned in DataSets which are...
| |
by: Mark Rae |
last post by:
Hi,
Am currently in the process of migrating a whole heap of v1.1 ASP.NET
solutions to v2.0, and would be interested to know what others are doing
about excluding files from projects.
I maintain several music websites which contain lots of static binaries
(newsletters, gig photos etc) which, once they are posted, never change.
In v1.1,...
|
by: Norman Crandall |
last post by:
I have a directory with about 20,000 other directories and files in it. I
need it in the root directory of the web application in order to write to
it. However, when I need to build the application. It takes forever. The
directory does not have anything in it that needs to be built. How can I
exclude the entire directory in ASP.NET 2.0,...
|
by: Brett Romero |
last post by:
Is there a way to have a file delete from Visual Source Safe if I
exclude (not delete) it from a Visual Studio project? I'd like what
ever is in the project to be reflected in VSS.
I'm using Studio integration with VSS.
Thanks,
Brett
|
by: =?Utf-8?B?UGl0Rw==?= |
last post by:
Here the facts as code sample:
Public Class Class1
Sub ABC(ByVal item As IUnit)
End Sub
End Class
Public Interface IUnit ' or any other Interface
ReadOnly Property Heureka() As Activator
ReadOnly Property Reference() As String
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |