简单的元组操作

时间:2012-06-05 13:54:12

标签: c-preprocessor

说我有一个元组:

#define T (a, b)

如何在不使用任何外部库的情况下在gcc中提取元组的第一个和第二个元素?

1 个答案:

答案 0 :(得分:3)

我找到了一种方法。我不确定这是否适用于除了gcc以外的任何其他内容。

#define first_(x, y) x
#define first(t) first_ t

#define second_(x, y) y
#define second(t) second_ t

#define T (a, b)

first(T) // expands to a
second(T) // expands to b