Tell me how to implement partitioning define.

There is a code:

#define F(t, n, v) tn = v; 

Calling:

 F(int, test, 1); 

OK.

I want to replace the parameters with defyne:

 #define T int, test2, 1 

Calling:

 F(T); 

It does not work, by the way the result takes the form:

 int, test2, 1 = ; 

That is, all variables are inserted into the first parameter.

How to tell the preprocessor to expand T as three parameters, not just one?

  • one
    But why? - Qwertiy
  • In this example, there is nothing, but when there is a list of variables that need to be passed to a bunch of other macros, such code acquires meaning and greatly simplifies writing code. - mikelsv
  • You will not be able to do this, because MSVC does not properly handle macros. Alas, oh, 2015 studio is no better. So either refuse such a decision, or from the studio. - ixSci 2:53
  • Or write your preprocessor. What I do. - mikelsv

2 answers 2

Maybe so?

 // tc #define F(t, n, v) tn = v; F(int, test, 1); #define T int, test2, 1 #define FFF(t, n, v) tn = v; #define FF(t) FFF(t) FF(T); 

Run the preprocessor

 avp@avp-xub11:hashcode$ gcc -E tc # 1 "tc" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "tc" int test = 1;; int test2 = 1;; avp@avp-xub11:hashcode$ 
  • Unfortunately in Visual Studio, this example is not collected with the same error. - mikelsv
  • What to do? Drop writing in Windows. - avp
  • This is the code for the project under Windows. When normal development tools appear in Linux, I’ll quit right away. - mikelsv
  • And I somehow emacs / make / bash / gcc / gdb is enough - avp
  • By the way, I wrote my preprocessor github.com/mikelsv/opensource/tree/master/msvxcc . He was wonderful, logical and all that kind, right up until #define A {. But separate #ifdef MSVXCCTEMPLATE processes it normally and solves the above problem. Unfortunately, it is still idle, although there is an idea to restore the code generator based on it and get rid of the templates. - mikelsv

To solve this problem, I wrote my preprocessor https://github.com/mikelsv/opensource/tree/master/msvxcc . Implementing additional notation :: indicating that parameters need to be deployed.

 #define A 1, 2, 3 #define B(a, b, ...) printf(a, __VA_ARGS__ ); B("%d %d %d\r\n", 1, 2, 3); B("%d %d %d\r\n", ::A); 

In the example, the last two lines will be identical, since A will be substituted in the form of its value.

  • Own, it's always great. As soon as I have time, I will definitely look. - avp