How to fail Compilation: Pragma?

Started by
7 comments, last by Prozak 22 years, 3 months ago
I would like to fail compilation, if certain events occur, using #ifdef, and others. How do i go about accomplishing this?

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

Advertisement
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!
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)

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
#ifndef USING_DX_INPUT
#error Direct Input not defined // works on both vc++ and borland
#endif
humanity will always be slaved by its ignorance
Thanx, it works just like i wanted !!

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

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)

in VC++ (6.0), go to your Project-Settings, C/C++, Preprocessor definitons and enter your Macros there
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!

This topic is closed to new replies.

Advertisement