Jump to content

  • Log In with Google      Sign In   
  • Create Account

Macro and GCC Compiler problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 asvsfs   Members   -  Reputation: 157

Like
0Likes
Like

Posted 08 July 2013 - 01:15 AM

Hi,

 

i have a bit of problem with getting a macro working with gcc compiler ,

im working with marmalade SDK and when compiling my code with arm gcc compiler it shows an error , im using one of gamedev article source code for object factory

 

Source Code Attached.

 

and here is the errors

Error    9    error : macro "MACRO_REPEAT_1" passed 5 arguments, but takes just 4   

Error    10    error : unterminated argument list invoking macro "MACRO_REPEAT_1"  

 

Thanks

Amir

Attached Files



Sponsor:

#2 Tribad   Members   -  Reputation: 887

Like
2Likes
Like

Posted 08 July 2013 - 01:25 AM

At which line in what file?

Anyways an explanation of what you expected these macros do would be nice. I am not a friend of macros because you do not know what gets passed to the compiler after pre-processing. And in C++ the most of that kind of macros can be realized as templates or classes.

 

So what these macros should do?



#3 BitMaster   Crossbones+   -  Reputation: 4427

Like
2Likes
Like

Posted 08 July 2013 - 01:40 AM

I assume you are trying to compile it with gcc or something like that? The problem then could be that this only causes a warning on MSVC, while gcc decides to treat the (obvious) problem as an error. It's possible you could pass some flag to gcc to not treat it as an error but a better path would be to check the library's mailing list/forum on information how to deal with that.
Should it turn out to be something like "we really just compile on MSVC and ignore warnings" then I would suggest to find a different library to use. That will not end well any which way.

#4 asvsfs   Members   -  Reputation: 157

Like
0Likes
Like

Posted 08 July 2013 - 01:42 AM

here is an example of what it do

 

ObjectFactory<Shape *(int), std::string> shape_factory;

shape_factory.Register<Triangle>("triangle");
shape_factory.Register<Square>("square");


Shape *shape1 = shape_factory.Create("triangle", 10);
Shape *shape2 = shape_factory.Create("square", 20);

 

it gives error at first line

 

its working nice when compiling with msvc default compiler , and no related warning


Edited by asvsfs, 08 July 2013 - 01:45 AM.


#5 Tribad   Members   -  Reputation: 887

Like
1Likes
Like

Posted 08 July 2013 - 03:04 AM

This is why I said using macros this way is bad. It is nearly impossible to find the cause for the error, because it is totaly unclear what the pre-processor creates as input.

 

Do you use the gcc on windows or on linux?

 

But what do the macros do? I do not understand their usage nor their purpose. Without some hints what you expect will happen its hard to find an anchor for the investigation.


Edited by Tribad, 08 July 2013 - 03:16 AM.


#6 asvsfs   Members   -  Reputation: 157

Like
0Likes
Like

Posted 08 July 2013 - 03:14 AM

im using gcc on windows and its not the latest version i guess its 4.4.1 or 4.5.2



#7 Tribad   Members   -  Reputation: 887

Like
2Likes
Like

Posted 08 July 2013 - 03:40 AM

I suspect the passing of a comma as a macro. This would change the number of parameters passed or expected so it do not match.

This may happen because of different implementations of how the usage of macros within macros is handled.

 

Different strategies, different results.

 

You may change the definition of the MACRO_COMMA_SEPERATOR from "," to an a

 

If I am right the macro processing passes on but the compiler will complain about weird code. (who wonders).



#8 asvsfs   Members   -  Reputation: 157

Like
0Likes
Like

Posted 09 July 2013 - 04:21 AM

Hey ,

 

changing it to an "a" ?!

 

well that doesn't work

 

its a comma distinct parameter from each other



#9 Tribad   Members   -  Reputation: 887

Like
0Likes
Like

Posted 09 July 2013 - 07:33 AM

#define m(a,b) do a b

 

#define bla m(MACRO_COMMA_SEPERATOR, d)

 

Using bla makes

 

m(,,d)

 

You are getting a wrong parameter count. If you change the definition for MACRO_COMMA_SEPERATOR to something that is an identifier, an a, you get

 

m(a,d)

 

The error message you cited is coming from the c pre-processor not from the compiler. Thats to different things. With the "a" the compiler will not understand what you want but pre-processor will let it pass.

 

Doing the change as I suggest will check whether passing the MACRO_COMMA_SEPERATOR makes a problem. If the error message stays as before search for another problem.



#10 Pink Horror   Members   -  Reputation: 1229

Like
0Likes
Like

Posted 10 July 2013 - 07:36 PM

Doesn't this belong in Coding Horrors?

 


///////////////////////////////////////////////////////////////////////////////
// 
// MacroRepeat
// 
// This header provides macros for repeating code.
// 
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2004 Robert Geiman.
//
// Permission to copy, modify, and use this code for personal and commercial
// software is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without any expressed or implied warranty.
//
// Any comments or questions can be sent to: rgeiman@buckeye-express.com
//
///////////////////////////////////////////////////////////////////////////////
 
#ifndef MACRO_REPEAT_H
#define MACRO_REPEAT_H
 
 
#define MACRO_EMPTY_SEPERATOR 
#define MACRO_COMMA_SEPERATOR ,
#define MACRO_SEMICOLAN_SEPERATOR ;
#define MACRO_BEGIN_PAREN_SEPERATOR (
#define MACRO_END_PAREN_SEPERATOR )
 
#define MACRO_EMPTY_MACRO(num)
#define MACRO_TEMPLATE_PARAMETER(num) typename A##num
#define MACRO_TEMPLATE_ARGUMENT(num) A##num
#define MACRO_FUNCTION_PARAMETER(num) A##num a##num
#define MACRO_FUNCTION_ARGUMENT(num) a##num
 
 
#define MACRO_REPEAT_0(begin_seperator, seperator, macro, end_seperator) 
#define MACRO_REPEAT_1(begin_seperator, seperator, macro, end_seperator) begin_seperator macro(0) 
#define MACRO_REPEAT_2(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_1(begin_seperator, seperator, macro, end_seperator) seperator macro(1) end_seperator
#define MACRO_REPEAT_3(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_2(begin_seperator, seperator, macro, end_seperator) seperator macro(2) end_seperator
#define MACRO_REPEAT_4(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_3(begin_seperator, seperator, macro, end_seperator) seperator macro(3) end_seperator
#define MACRO_REPEAT_5(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_4(begin_seperator, seperator, macro, end_seperator) seperator macro(4) end_seperator
#define MACRO_REPEAT_6(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_5(begin_seperator, seperator, macro, end_seperator) seperator macro(5) end_seperator
#define MACRO_REPEAT_7(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_6(begin_seperator, seperator, macro, end_seperator) seperator macro(6) end_seperator
#define MACRO_REPEAT_8(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_7(begin_seperator, seperator, macro, end_seperator) seperator macro(7) end_seperator
#define MACRO_REPEAT_9(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_8(begin_seperator, seperator, macro, end_seperator) seperator macro(8) end_seperator
#define MACRO_REPEAT_10(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_9(begin_seperator, seperator, macro, end_seperator) seperator macro(9) end_seperator
#define MACRO_REPEAT_11(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_10(begin_seperator, seperator, macro, end_seperator) seperator macro(10) end_seperator
#define MACRO_REPEAT_12(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_11(begin_seperator, seperator, macro, end_seperator) seperator macro(11) end_seperator
#define MACRO_REPEAT_13(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_12(begin_seperator, seperator, macro, end_seperator) seperator macro(12) end_seperator
#define MACRO_REPEAT_14(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_13(begin_seperator, seperator, macro, end_seperator) seperator macro(13) end_seperator
#define MACRO_REPEAT_15(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_14(begin_seperator, seperator, macro, end_seperator) seperator macro(14) end_seperator
#define MACRO_REPEAT_16(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_15(begin_seperator, seperator, macro, end_seperator) seperator macro(15) end_seperator
#define MACRO_REPEAT_17(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_16(begin_seperator, seperator, macro, end_seperator) seperator macro(16) end_seperator
#define MACRO_REPEAT_18(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_17(begin_seperator, seperator, macro, end_seperator) seperator macro(17) end_seperator
#define MACRO_REPEAT_19(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_18(begin_seperator, seperator, macro, end_seperator) seperator macro(18) end_seperator
#define MACRO_REPEAT_20(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_19(begin_seperator, seperator, macro, end_seperator) seperator macro(19) end_seperator
#define MACRO_REPEAT_21(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_20(begin_seperator, seperator, macro, end_seperator) seperator macro(20) end_seperator
#define MACRO_REPEAT_22(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_21(begin_seperator, seperator, macro, end_seperator) seperator macro(21) end_seperator
#define MACRO_REPEAT_23(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_22(begin_seperator, seperator, macro, end_seperator) seperator macro(22) end_seperator
#define MACRO_REPEAT_24(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_23(begin_seperator, seperator, macro, end_seperator) seperator macro(23) end_seperator
#define MACRO_REPEAT_25(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_24(begin_seperator, seperator, macro, end_seperator) seperator macro(24) end_seperator
#define MACRO_REPEAT_26(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_25(begin_seperator, seperator, macro, end_seperator) seperator macro(25) end_seperator
#define MACRO_REPEAT_27(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_26(begin_seperator, seperator, macro, end_seperator) seperator macro(26) end_seperator
#define MACRO_REPEAT_28(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_27(begin_seperator, seperator, macro, end_seperator) seperator macro(27) end_seperator
#define MACRO_REPEAT_29(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_28(begin_seperator, seperator, macro, end_seperator) seperator macro(28) end_seperator
#define MACRO_REPEAT_30(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_29(begin_seperator, seperator, macro, end_seperator) seperator macro(29) end_seperator
#define MACRO_REPEAT_31(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_30(begin_seperator, seperator, macro, end_seperator) seperator macro(30) end_seperator
#define MACRO_REPEAT_32(begin_seperator, seperator, macro, end_seperator) MACRO_REPEAT_31(begin_seperator, seperator, macro, end_seperator) seperator macro(31) end_seperator
 
 
#define MACRO_LIST(num, macro) MACRO_REPEAT_##num(MACRO_EMPTY_SEPERATOR, MACRO_COMMA_SEPERATOR, macro, MACRO_EMPTY_SEPERATOR)
#define MACRO_LIST_APPEND(num, macro) MACRO_REPEAT_##num(MACRO_COMMA_SEPERATOR, MACRO_COMMA_SEPERATOR, macro, MACRO_EMPTY_SEPERATOR)
#define MACRO_LIST_PREPEND(num, macro) MACRO_REPEAT_##num(MACRO_EMPTY_SEPERATOR, MACRO_COMMA_SEPERATOR, macro, MACRO_COMMA_SEPERATOR)
#define MACRO_BEGIN_PAREN(num, macro) MACRO_REPEAT_##num(MACRO_BEGIN_PAREN_SEPERATOR, MACRO_EMPTY_SEPERATOR, macro, MACRO_EMPTY_SEPERATOR)
#define MACRO_END_PAREN(num, macro) MACRO_REPEAT_##num(MACRO_END_PAREN_SEPERATOR, MACRO_EMPTY_SEPERATOR, macro, MACRO_EMPTY_SEPERATOR)
#define MACRO_REPEAT(num, macro) MACRO_REPEAT_##num(MACRO_EMPTY_SEPERATOR, MACRO_EMPTY_SEPERATOR, macro, MACRO_EMPTY_SEPERATOR)
 
 
#endif



#11 Khatharr   Crossbones+   -  Reputation: 3037

Like
1Likes
Like

Posted 10 July 2013 - 09:08 PM

Dear Robert Geiman,

 

If you ever, ever do something like this again...

 

...DON'T SIGN IT!

 


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#12 DemonRad   Members   -  Reputation: 290

Like
0Likes
Like

Posted 12 July 2013 - 12:48 AM

switch to GCC 4.7/4.8 and use variadic templates ^^ no longer macros for this kind of stuff

 

@Khatharr. there are also few 3d engines that are using a similiar macro :D +1 for expressing disappoint using such macros


Edited by DemonRad, 12 July 2013 - 12:50 AM.

Peace and love, now I understand really what it means! Guardian Angels exist! Thanks!





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS