Archived

This topic is now archived and is closed to further replies.

Prozak

How to fail Compilation: Pragma?

Recommended Posts

Oluseyi    2103
You''ll need to be a bit more specific. There''s a ton of things that can be done using the preprocessor (look up the __FILE__ and __LINE__ identifiers, which can return compile-tiime error information for example). Also take a look at the MSVC-specific #pragma message, #pragma warning( error : xxxx ), #warning and #error preprocessor/conditional directives.

Happy Hacking!

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
Prozak    898
I''m using VC++6, and will only be using it,
lets say:
#define USING_DX_INPUT

now, later:
#ifndef USING_DX_INPUT
do something that will fail compile here!
#endif

see? I just want to fail compile, using some directives...

[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing."
- Wernher Von Braun (1912-1977)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I think you just stated your own solution:

#ifndef USING_DX_INPUT
do something that will fail compile here!
#endif

type exactly this into your source.

Or better:

#ifndef USING_DX_INPUT
You must define Direct Input !
#endif

Share this post


Link to post
Share on other sites
Prozak    898
oops, theres one thing that isn''t working the way it should.
In one file I have "#def alpha",
and in another I have "#ifndef alpha (do stuff...)""

Basicly, there''s one file in my project that requires the
presence of another file.
Lets call them A and B, B needs A to function properly.
So, in A I have:
#def A_PRESENT

And in B i have:
#ifndef A_PRESENT
#error You need file A.h to compile this correctly
#endif

The problem is, I think, the compiler goes over B first,
and because A_PRESENT isn''t yet defined, it automaticly fails,
although A is present...

Anyone can help me change the order of compilation, or force
all the defines to be defined before compilation starts?

How do I work arround this one?
Thsnx for any help,







[Hugo Ferreira][Positronic Dreams][]
"Research is what I''m doing when I don''t know what I''m doing."
- Wernher Von Braun (1912-1977)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
in VC++ (6.0), go to your Project-Settings, C/C++, Preprocessor definitons and enter your Macros there

Share this post


Link to post
Share on other sites
Oluseyi    2103
quote:
Original post by pentium3id
And in B i have:
#ifndef A_PRESENT
#error You need file A.h to compile this correctly
#endif

Try this instead:
// B.h
#include "A.h"

#ifndef A_PRESENT
#error You need file A.h to compile this correctly
#endif

Since you explicitly include A in B this time, A should be processed first. Alternatively, you could include both files in another header C, A first. That should also yield the same result (so long as all other files include A and/or B through C).

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites