linderd
7/1/2011 1:32:00 AM
Howdy,
I'm using the following hackery to define namespaces for structs:
#define GENERIC_NS_PREFIX default_
#define GENERIC_CONCAT(p1, p2) GENERIC__CONCAT(p1, p2)
#define GENERIC__CONCAT(p1, p2) p1 ## p2
#define $(name) GENERIC_CONCAT(GENERIC_NS_PREFIX, name)
#undef GENERIC_NS_PREFIX
#define GENERIC_NS_PREFIX namespace1_
struct $(List) *list;
#undef GENERIC_NS_PREFIX
#define GENERIC_NS_PREFIX namespace2_
struct $(List) *list;
This works perfectly, and yields:
arc:~ douglasl$ cc -E junk.h
# 1 "junk.h"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "junk.h"
struct namespace1_List *list;
struct namespace2_List *list;
So, my question is this:
Why do I need three macros to do, essentially:
#define X x
#define Y(y) X ## __ ## y
Surely there is some syntax I can use that doesn't require 3 nested macros to achieve this?
cheers,
Doug.