Jump to content
Sign in to follow this  
SnakeByte

Templates And Bad #defines

Recommended Posts

Using BoostC 2.2.5 Beta, if I try to compile the following code, I get the errors I would expect to get when something isn't properly defined:

 

#include <system.h>

#define TEST randomstring

void main()
{
int someValue = TEST;
}

 

defineTest.c(7:18): error: unknown identifier 'randomstring'

defineTest.c(7:16): error: failed to initialize variable 'someValue'

...

 

Same goes with normal template usage.. I get the same appropriate error:

 

#include <system.h>

#define INT_VALUE randomstring

template <class T>
T GetMax (T a, T b) {
 return (a>b)? a : b;
}

void main ()
{
 int i=2, j;
 j=GetMax<int>(INT_VALUE,i);
}

 

defineTest.c(13:16): error: unknown identifier 'randomstring'

defineTest.c(13:16): error: unknown template identifier 'GetMax'

...

 

but when I attempt to layout my code like how the current lcd_driver.h does it, the unknown identifier error vanishes and I'm left with the generic "failed to generate expression":

 

#include <system.h>

#define INT_VALUES	1,  randomstring

#define getmax	GetMax<INT_VALUES>

template <int a, int b> int GetMax( void ) 
{
 return (a>b)? a : b;
}

void main ()
{
 int j;
 j=getmax();
}

 

defineTest.c(15:4): error: failed to generate expression

defineTest.c(15:4): error: invalid operand 'GetMax<1, randomstring>()'

defineTest.c(15:3): error: failed to generate expression

 

 

Now, the second error should help me determine what's going on, but depending on the code that's written, that 2nd error doesn't always occur and I'm only left with the "failed to generate expression" errors. Depending on the amount of nesting being done with the #defines, this can make troubleshooting a big pain in the ... :)

 

Just as a FYI, I found that if attempt to compile this code with gcc, that I am given the error, so this might be worth trying if anyone else is having trouble identifying why that error is happening.

 

gcc test.cpp -I ./include/ -D_PIC16F876 -D_BOOSTC

test.cpp:15: `randomstring' undeclared (first use this function)

test.cpp:15: template argument 2 is invalid

test.cpp:15: no matching function for call to `GetMax()'

 

 

Thanks!

Share this post


Link to post
Share on other sites

SnakeByte

 

Using BoostC 2.2.5 Beta, if I try to compile the following code, I get the errors I would expect to get when something isn't properly defined:

 

#include <system.h>

#define TEST randomstring

void main()
{
   int someValue = TEST;
}

 

Did you try it with the string quotation marks?

 

#define TEST "randomstring"

 

or

 

int SomeValue = "TEST";

 

DarrenJ

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...