1

I know the option -E enables the proprocessed output from a c source file. But I want further to have the macros fully evaluated.

As a trivial example, in the following snippet,

# define P(n) n, n^1, n^1, n
const bool array[4] = {P(0)};

I want to see the exact values of elements in array[4]. But the -E output only shows 0, 0^1, 0^1, 0 etc. So how to make it to show 0, 1, 1, 0 in fully evaluated form here?

Thanks.

3 Answers 3

3

I think you've misunderstood the role of the preprocessor. The preprocessor expands macros. 0, 0^1, 0^1, 0 is as fully expanded as possible. From there it's up to the next stage of compilation to interpret the numerical expressions. The next stage at which you can see the output for gcc is the generation of assembly code for which you can use gcc -S.

Sign up to request clarification or add additional context in comments.

Comments

1

That is its fully evaluated form. The preprocessor doesn't do constant-folding, the compiler does.

3 Comments

Oh, I guess I was asking how to get constant-folding in addition to preprocessing. Is there a way to do this?
Not at the preprocessing stage, you can go to the assembly code and find it there.
Yes, I saw that. But ideally I still want it to be in the array assignment form. Looks like output from -S gives me a column here.
0

The output you got is the fully preprocessed code. What you want is made during compilation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.