Announcement: Be excellent to each other.


Caravel Forum : Caravel Boards : Development : GCC/MSVC question.
New Topic New Poll Post Reply
Poster Message
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon GCC/MSVC question. (0)  
I have a project where it is necessary to have many, many stub functions with unused parameters. The project must also compile under both GCC and MSVC. A function like this:

void DogFunc(char HappyBone)
{ }


...will generate an unused variable warning in GCC. I can get around this by enclosing the variable name in comments, like so:

void DogFunc(char /* HappyBone */ )
{ }


...but then VC will not compile it, giving me "error C2055: expected formal parameter list, not a type list".

I can do some dummy assigns on the parameters to get both compilers to shut up, but maybe there is a more elegant solution?

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
01-10-2005 at 10:51 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: GCC/MSVC question. (0)  
I talked to some other people and the solution I have is to just make dummy assigns, but put it in an UNUSED() macro to make the code look a little cleaner.

#define UNUSED(x) x = x

void DogFunc(char HappyBone)
{
  UNUSED(HappyBone);
}


What a finicky fellow I am.

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
01-11-2005 at 01:59 AM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
bradwall
Level: Smiter
Avatar
Rank Points: 423
Registered: 02-12-2003
IP: Logged
icon Re: GCC/MSVC question. (0)  
In VC++, if you set the warning level to 4 you will also get the warning:

warning C4100: 'HappyBone' : unreferenced formal parameter

You can disable this specific warning by adding the following line at the top of your code:

#pragma warning(disable: 4100)

I'm not sure how to do this with GCC
01-11-2005 at 03:07 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
trick
Level: Legendary Smitemaster
Rank Points: 2580
Registered: 04-12-2003
IP: Logged
icon Re: GCC/MSVC question. (+1)  
There's a gcc option you can use. If you pass the -Wno-unused-parameter option to gcc, it won't complain about unused parameters. You could also fix it in the source code itself by using variable attributes (should be available in any version of gcc you'd want to use, I think):
void DogFunc(char HappyBone __attribute__((__unused__)))
{
  ...
}

You'll need a macro to make that portable though:
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
#else
#define UNUSED
#endif

void DogFunc(char HappyBone UNUSED)
{
  ..
}

I have no idea why I didn't use this in DROD.

- Gerry
01-12-2005 at 04:19 AM
View Profile Send Private Message to User Send Email to User Show all user's posts Quote Reply
New Topic New Poll Post Reply
Caravel Forum : Caravel Boards : Development : GCC/MSVC question.
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.