176 questions
0
votes
2
answers
33
views
I need this file to stringify a book, a chapter, and a verse but it stringifies multiple books at once
This file splits the text variable from book, chapter, and verses. It should ideally look like this:
[
{
"book": "PLACEHOLDER",
"chapters": [
{
&...
1
vote
0
answers
48
views
C preprocessor: stringizing multiple levels of function-like macros
I'm working with multiple levels of macros where I rely on stringification of the parameters. My own functions have quite a few parameters already and stringizing them effectively doubles the number ...
1
vote
0
answers
38
views
Incorporate constant into byte array as ASCII correct code
I have some numeric constants in my data definition and would like to be able to use them inside my strings without having to embed them at runtime. Is this possible in MASM?
.data
LOWER_BOUND = 50
...
0
votes
1
answer
178
views
Use concatenation and stringizing in the same macro with GCC
Those macros are compiled without error with visual studio and codewarrior compilers. With gcc the error is shown in the comment
#define STRINGIFY(x) #x
#define MYINC(n) STRINGIFY(extensions/##n#...
0
votes
1
answer
297
views
Why can't GCC's typeof() be stringified?
I'd like to print the type that typeof() outputs, but typeid is only available in C++. Why can't I use stringification to get the name of this type?
#define GET_STRING(s) #s
#define example(input) ...
0
votes
1
answer
64
views
How to merge 2 serializable functions into 1 serializable function in JS?
As you know, there are certain cases (e.g., use in workers) when functions need to be serializable (and, at the other side, deserializable of course). I have such a case; a library function (i.e. I ...
2
votes
1
answer
647
views
How to contain escape sequences in macro definition #?
I am trying to use this macro definition in C:
#define STR(x) #x
Is it possible to contain some escape sequences inside x? e.g., I want to define a string like:
char* str = "\'";
This ...
0
votes
1
answer
183
views
Stringify a template numeric argument
I have the following piece of code:
template<int maxRegNum> void f(MuliInstr instr);
template<> void f<0>(MuliInstr instr)
{
if (instr.regA == 0) asm volatile ("mov r4, r0&...
0
votes
1
answer
56
views
How to access structure member with stringification (using ## or # in C macro)?
typedef enum
{
ENUM1_A=0,
ENUM1_B,
}someEnum1_e;
typedef union
{
someEnum1_e value;
}someEnum1_e_t;
#define GET_ELEMENT(data_name) blah.#data_name
int main (void)
{
...
1
vote
2
answers
558
views
C Preprocessor stringification (again) [duplicate]
Is it possible to have stringification after numeric evaluation?
This is better explained with a simple example:
#define A 1
#define B 2
#define SUM (A + B)
#define STR_IMPL_(x) #x
#define STR(x) ...
4
votes
3
answers
3k
views
`JSON.stringify` omits custom keys in array
I am storing my array as a mixture of array an array and an object. For example assume this one:
let arrObj = [];
arrObj["x"] = 12;
arrObj.push(12);
arrObj["y"] = 15;
arrObj.push(15);
// result: ...
6
votes
2
answers
145
views
What does Any.match do?
It has the deceivingly simple code:
method match(Any:U: |) { self.Str; nqp::getlexcaller('$/') = Nil }
However, this is the behavior it has:
(^3).match(1) # OUTPUT: «「1」»
So far, so good.
say (...
1
vote
1
answer
508
views
How to stringify char buffer for C macro
I have a LOG(fmt, ...) macro that does not work when using a char buf[] as fmt.
The code below is a complete (not actually) working example of the code. In some_function(), I am trying to use LOG() ...
-1
votes
1
answer
57
views
Accessing and modifying variables using token concatenation in C
I've been reading about stringification and token pasting and I was trying to access a variable using token pasting and modifying it's value. Is such a thing possible?
Suppose variables a0 and a1 are ...
2
votes
3
answers
981
views
Cpp : How to understand and/or debug complex macros?
I am trying to learn preprocessor tricks that I found not so easy (Can we have recursive macros?, Is there a way to use C++ preprocessor stringification on variadic macro arguments?, C++ preprocessor ...
0
votes
1
answer
521
views
Is it possible to process math calculation before stringify a macro?
I look through a lot of examples online about macro stringification but can't find something similar.
I currently have the definitions as below.
#define PIN_A (0+1)
#define PIN_B (0+2)
#define PIN_C ...
0
votes
2
answers
286
views
C stringification: convert constant to integer [closed]
I need to convert defined constants to their integer values so I came up with this macro (STR_TO_CONST) for doing so...
#define STRFY_VAL(s) #s
#define STRFY_KEY(s) STRFY_VAL(s)
#define STR_TO_CONST(...
3
votes
1
answer
140
views
How can I stringify a macro using a macro?
#define A_1 {2,1124,124110,2,0,20,5121,0,21241,10}
#define SFY(macro) #macro
void func(char* s, int i) {
printf("%d %s", i, s);
}
int main (void) {
int a[10] = A_1;
func(SFY(A_1), 2);
}
...
4
votes
0
answers
55
views
how to concatenate strings in #include statement [duplicate]
How do I concatenate two strings in an include statement?
I tried the code below - and also without ## - but both times, only the BASE_DIR part was output by the preprocessor.
#define BASE_DIR "...
5
votes
2
answers
5k
views
Hash symbol after define macro? [duplicate]
What does the '#' symbol do after the second define? And isn't the second line enough? Why the first one?
#define MAKESTRING(n) STRING(n)
#define STRING(n) #n
0
votes
2
answers
136
views
gcc Stringification of expression with "%" sign
I`m trying to compile the following program
#include <stdio.h>
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
#define FOO(expression)\
printf("prefix" __stringify(...
3
votes
0
answers
107
views
Strange token stringification in C with linux-* variable or string [duplicate]
This is the first question in stackoverflow. So far I got so many help from here. Thanks!
I have the following simplified code:
#define str(s) str2(s)
#define str2(s) #s
#define T_A linux-x86_64
...
0
votes
1
answer
154
views
Macro inside a Function and stringfication
I have the following function foo() and the macro FOO(str).
void foo(const char *fmt, ...) {
va_list args;
va_start(args,fmt);
vsprintf(msgbuff,fmt,args);
va_end(args);
printf("%s\n",...
2
votes
1
answer
85
views
Escaping a char * in C
I had to made something for a little programm some days ago, I needed to turn a string like "foo\n" into its stringified form (something like "\"foo\\n\"").
But I found nothing, so I ended up writing ...
1
vote
1
answer
61
views
String handling inside Preprocessor macro
I need to change a implementation of Macro(LOGGING_MACRO)
printf into syslog.
Macro Usage :
LOGGING_MACRO(5,("Value of x,y=%d,%d\n",x,y));
Def1 :
#define LOGGING_MACRO(loglevel,str) printf str;...
1
vote
2
answers
56
views
Macro stringifies a previous macros identifier instead of its replacement [duplicate]
Why is inner_LOAD_ATOM(buffer, ATOM_MAX) converted to scanf("%" "ATOM_MAX" "s", x) but the wrapped version isnt? I would expect ATOM_MAX(identifier) to be replaced by 10 before it is "passed" to ...
1
vote
2
answers
196
views
C Preprocessor to compute product specific include
I have to maintain C code that has both generic components and product specific components. I would like to simplify my code so that I have just one generic product.h file which has a structure like
#...
0
votes
0
answers
487
views
Macro to stringify the result of an arithmetic expression
Is it possible to write a preprocessor macro which stringifies the result of an integer arithmetic expression in clang?
For example:
#define WIDTH 20
#define HEIGHT 30
int main()
{
puts("The ...
0
votes
1
answer
2k
views
C++ namespace as a macro value
I have simple delegate functions in my C++ test code. Since I cannot include the original implementation .cpp files(embedded ones), I use delegate .cpp file in the tests that are running on PC. My ...
0
votes
2
answers
277
views
Changing Host side code for openCL C++ after stringifying the kernel code
I am working on a project where I am using openCL C++ bindings. I have a kernel.cl file that is read from the host side and loaded and executed. But now I want to embed it into my .cpp file so I can ...
1
vote
1
answer
419
views
Delayed stringification without macro expansion
Is it possible to modify the following code fragment to prevent the diagnostic printed by #pragma GCC warning from changing if any of the identifier tokens in deprecation_message are defined as ...
1
vote
1
answer
45
views
Wrong use of stringification
Given the following code:
#define MY_STRINGIFY_MACRO(...) #__VA_ARGS__
#define PORT_MAC(portNum) port: portNum
#define LOG_MACRO(...)
printf( MY_STRINGIFY_MACRO(__VA_ARGS__) )
void func(int ...
1
vote
1
answer
115
views
Stringification macro always adds a single space character
Given the following code that prints a string which is a stringification of two words:
#define PORT_INFO_MAC_2(portNum) port: portNum
#define PORT_INFO_MAC(portNum) PORT_INFO_MAC_2(portNum)
/*...
10
votes
2
answers
4k
views
Stringify Macro with Unicode String Literal
I'm using this preprocessor macro to "stringify" and return easily from a definition resolving function:
#define STRINGIFY_RETURN(x) case x: return #x ""
It works like a charm in MBSC ...
0
votes
0
answers
170
views
c# Generic way to stringify arrays of structs
I've searched for quite some time, but I have not been able to find how to generically stringify an array of structures in C# at runtime.
Let's say I have
public enum FieldInfoType
{
FitUInt32,
...
0
votes
1
answer
72
views
Stringize loopcounter to reference members of C struct
I have two structs that appears like:
typedef unsigned char byte;
struct my_struct_2 {
int type;
int length; //will be 2 in this case
byte value1; //MSB
byte value2; //LSB
}
struct my_struct_4 {
...
0
votes
1
answer
148
views
Stringify Endpoint for Xcode LLVM Processor Macros
In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as:
STR(arg)=#arg
HUBNAME=STR("myhub")
HUBLISTENACCESS=STR("Endpoint=sb://abc-xyz....
1
vote
1
answer
331
views
Eclipse CTD macro syntax error
I am using the following macro successfully.
#define SECTION(a) __attribute__ ((section(#a)))
Now in the same file I defined a new macro, and I tried using it in my code:
#define GP_RAM_DATA_1 ...
0
votes
3
answers
311
views
save expanded macro result before it is undefined
With GCC, I am using X-macros for a collection of variables.
#define TEST_MAP \
X(0, 1, 2) \
X(0, 2, 2) \
X(0, 3, 5)
Let's suppose I need to sum up all the 2nd fields
#...
2
votes
2
answers
204
views
How can I add Integer using '##' in C preprocessor?
#include<stdio.h>
#define DEF6 625
#define DEF6 625
#define DEF(n) DEF##n
void main(){
printf("%d\n", DEF(6));
}
This code works.
but
#include<stdio.h>
#define DEF6 625
#define ...
2
votes
2
answers
471
views
Can I use token-pasting and/or stringizing for #includes?
Let's say I've got a few files, that are all similarly named: Foo1Bar.h, Foo2Bar.h, Foo3Bar.h, etc etc. Now, I want to auto-include those in some main.c in a "plug-in" style, that is, I don't want to ...
1
vote
1
answer
71
views
Is there a macros to see my code in runtime?
For debugging purposes, I want to print the passed argument, like
def myfunc(arg: MyType) = println(str_macro(arg) + " = " + arg)
I know, I can define mine own. But, the thing seems to be standard. ...
1
vote
3
answers
103
views
Construct fixed string by concatenating macro with string
I've went through a number of similar questions and almost got it to work, but not quite.
What I have is the standard Macro-Expansion-Stringification-method.
#define QUOTEME(M) #M
#define ...
11
votes
1
answer
2k
views
Macro substitution in #include directive
I would like to use an #include directive with a file name that is passed as an externally defined macro.
E.g.
#include #FILE".h"
where FILE would be defined as the string MyFile (without quotes), ...
1
vote
4
answers
4k
views
How to create a string from a pre-processor macro with arguments
I'm trying to stringify a macro in System Verilog, so I can use it in a string for printing.
I created a STRINGIFY macro:
`define STRINGIFY(x) `"x`"
as suggested here:
How to create a string from a ...
4
votes
1
answer
139
views
How to embed an integer in a macro string? [duplicate]
My first time seeing stringification and token pasting. I feel like it could be a good tool for this macro:
#define MY_NUMBER 3
#define MY_STRING "the number three: ##MY_NUMBER"
printf("%s\n", ...
0
votes
1
answer
201
views
Postgres 9.2 select star into an array
I want to do something like this inside a stored procedure so I can see the result of an insert statement for debugging:
thing := array_to_string(ARRAY(select * from some_table limit 1 ));
raise info ...
8
votes
3
answers
2k
views
Stringify macro with GNU gfortran
How can I stringify a preprocessor macro with GNU gfortran? I would like to pass a macro definition to GNU gfortran which will then be used as a string in the code.
Effectively I would like to do ...
4
votes
2
answers
506
views
How to stringify an arithmetic result in a preprocessor macro
How should I write a macro that receive two arguments and (giving for example 3 and 2) return the following output?
The sum of 3 and 2 is 5
That is what I write, but it doesn't compile:
#define ...
3
votes
1
answer
2k
views
Preprocessor Stringizing Operator with String Literal Prefixes
So I want to do the traditional thing to do with the stringizing operator in a macro:
#define FOO(x) foo(#x, (x))
However I need to use a string literal prefix: http://en.cppreference.com/w/cpp/...