Need help tracking down a syntax error

I have a file where I keep some common switches and modes in the form of preprocessor directives, and for some reason my compiler (VC++) is giving me errors, but I don't really understand why:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef __PREPROCESSOR_DIRECTIVES_H
#define __PREPROCESSOR_DIRECTIVES_H

#include <iostream>

using namespace std;

/*
 * Code environment parameters:
 * Define choices here
 */
//#define __MODE_VERBOSE
//#define __MODE_DEBUG
#define __MODE_SIZE_BASED_COMMUNITY_SECONDARY_SUBORDER

// Debug mode
#ifdef __MODE_DEBUG 
	cout << "Debug Mode: ON" << endl;
#else
	cout << "Debug Mode: OFF" << endl; //error C2143: syntax error : missing ';' before '<<'
#endif

// Verbose mode
#ifdef __MODE_VERBOSE 
	cout << "Verbose Mode: ON" << endl;
#else
	cout << "Verbose Mode: OFF" << endl; error C2143: syntax error : missing ';' before '<<'
#endif

// Community secondary suborder mode
#ifdef __MODE_SIZE_BASED_COMMUNITY_SECONDARY_SUBORDER
	#define __COMMUNITY_SECONDARY_SUBORDER_CONDITION (rand_member->synapses_per_brain*rand_member->B->size()>=(*iC)->synapses_per_brain*(*iC)->B->size())
	cout << "Seconday Community Suborder Mode: SIZE-BASED" << endl; // error C2143: syntax error : missing ';' before '<<'
#else
	#define __COMMUNITY_SECONDARY_SUBORDER_CONDITION (rand()%1)
	cout << "Seconday Community Suborder Mode: RANDOM" << endl;
#endif

#endif 


Apparently it doesn't like my use of "cout", but I can't understand why! I'm sure it's something simple...
Last edited on
You can't put random statements in the middle of the landscape. They belong into functions.
Global using-directives don't belong into headers either.
Ok, thanks :)

But I didn't think that the rand() text itself was a function, I thought it was a preprocessor directive that only becomes a function once it is substituted elsewhere in the code. I thought preprocessor definitions have no syntax and are just text substitutions. Maybe I've misunderstood the use of these directives..

How can I achieve what I'm trying to do though? I have a condition which I've named __COMMUNITY_SECONDARY_SUBORDER_CONDITION which is evaluated elsewhere in my program:

1
2
3
//somewhere else:
if (__COMMUNITY_SECONDARY_SUBORDER_CONDITION)
    //do something 


Will I have to do an if/else in the code itself, replacing the entire if condition?
Last edited on
No, use inline functions.

How can I achieve what I'm trying to do though?

That kinda depends on what you're trying to do.
That kinda depends on what you're trying to do.


See above; I'm trying to have a macro define a condition, which will be evaluated later in the code. Basically something like this:

1
2
3
4
5
6
7
8
9
10
// Header file before main():
#ifdef __MODE_SIZE_BASED_COMMUNITY_SECONDARY_SUBORDER
	#define __COMMUNITY_SECONDARY_SUBORDER_CONDITION (rand_member->synapses_per_brain*rand_member->B->size()>=(*iC)->synapses_per_brain*(*iC)->B->size())
#else
	#define __COMMUNITY_SECONDARY_SUBORDER_CONDITION (rand()%1)
#endif

//somewhere else in a function/class somewhere:
if (__COMMUNITY_SECONDARY_SUBORDER_CONDITION)
    //do something  
Last edited on
Yeah, okay. That still doesn't explain what the cout statement is doing there.
You should still use inline functions for the conditions.
Last edited on
I should point out that this actually compiles and does seem to work, my problem is with the "cout" statements, although now that I think of it the problem is that the header was being called outside of main(), so this whole thread is kind of moot now anyway... :)
:O So many define macros
Topic archived. No new replies allowed.