GPWiki.org
GPWiki.org
It is currently Tue Jun 18, 2013 11:19 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Feb 24, 2013 10:26 pm 
Rookie
User avatar

Joined: Sun Feb 24, 2013 10:21 pm
Posts: 2
Does anyone know a way of doing a massive re-#define of a lot of variables with a common name (SDLK_ in this case) in one pre-processor directive? I'm creating an engine for the game I'm writing, and I'd like to make it as separated from the libraries used as possible in the actual game's code.


Top
 Profile  
 
PostPosted: Tue Feb 26, 2013 2:39 am 
Rookie
User avatar

Joined: Sun Feb 24, 2013 10:21 pm
Posts: 2
I found a solution:
Code:
#define example(key) SDLK_ ## key

This macro will replace "example(key)" with "SDLK_key," so example(k) would result in SDLK_k, or 107. The ## pre-processor directive concatenates the phrases before and after it, allowing concatenation of a variable from a macro and a common name from a set of variables to create a variable name for #defining. Good 'ol "The C Programming Language" came to the rescue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group