Does the # symbol have any definition in C? [duplicate] - c

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What do # and ## operators do in C?
I can't seem to word the proper google query for this question so I'll decided to ask you wonderful people.
I've seen # being used in macro definitions, but what the hell does it mean?
Reference: http://www.flipcode.com/archives/Faking_Templates_In_C.shtml
That begs a secondary question, are templates in C++ implemented using macros?

Read the GCC documentation on the cpp preprocessor. The # sign is used for stringification of macro arguments, and the double ## for concatenation
C++ templates are not implemented as preprocessor textual macros. You might feel them as being macros producing abstract syntax trees (of some core subset of C++).
FYI, Common Lisp has an even more powerful macro system.

## concats two tokens together, in the case of type##_InitVector, the content type with _InitVector.

Related

Warning in C compiler about unused enumeration [duplicate]

This question already has answers here:
Finding unused enum members in C
(3 answers)
Closed 1 year ago.
Is there a warning or some other technique/mechanism/tooling to clean up a C code from unused enumerations?
A solution for C++ code would also be interesting but the question is primarily about C.
Ideally if the solution was to be found based on GNU tools available in common tool chains.
Any compiler or other code analysis tool that is capable of listing unused enumeration members would be interesting to know about.
I am currently using gcc. -Wall is on. No warnings about unused enumeration members appear in the compilation log.
Thanks to an unknown user in the comments there is an answer. Apparently a tool named Splint is capable of finding unused enumeration members.
Here is a similar question Finding unused enum members in C asked before, where the aforementioned tool has been analyzed and accepted as a correct answer.

how to analyze a C header file? [duplicate]

This question already exists:
Is it possible to have gcc analyze my code and give me info about it [closed]
Closed 2 years ago.
I want to write a script that analyzes a C header file.
The header contains a few declarations of functions
The scrip needs to understand how many arguments each function has, and what are their types.
can gcc (or other tool) do this?
It comes down to how accurate you want to be when parsing a C header file. You could implement the C grammar for a function declaration and be guaranteed to parse it 100% correctly, but it will be a lot of work.
Conversely, a simple regex matcher is the easiest approach, but could have false-positive matches. You can implement a regex parser using C++, python or even other scripting languages such as bash or powershell. I would suggest python as its beginner friendly.
If you don't know what regex is, it's a simple language used to parse strings and extract data from strings. So you could create a regex expression to find the c function declaration then use that expression to pull out all of the arguments. Should be straight forward.
Create a regex expression on https://regex101.com/ and test it against teat strings, then implement that expression in python to do the work.

How to track c macro expansion? [duplicate]

This question already has an answer here:
How to see macro expansions step-by-step?
(1 answer)
Closed 5 years ago.
I'm trying to understand how preprocessor magic works and how I can adapt the approach for my needs. I do something wrong and compilation fails. I'd like to know at which expansion step there is a mistake and see expansion step by step. gcc -E works only for valid code, so I'm looking for a side tool to show expansion tree.
I like using Eclipse CDT which has a nice feature allowing to step through Macro expansions.

Where can I look to find platform macros? [duplicate]

This question already has answers here:
Why does the C preprocessor interpret the word "linux" as the constant "1"?
(5 answers)
Closed 8 years ago.
With in a source code I know you can use platform specific information such as
#ifdef __APPLE__
or
#ifdef __ANDROID__
I am working on a new platform and need to use such macros. Where does the definition occur? If it is done at the compiler, where can i look to find this information?
It is said that the NaCl MACRO for instance is defined at the compiler as follows:
/* The NACL compiler defines __native_client__ and __pnacl__
* Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi
*/
EDIT:
I guess I'm Looking for predefined compiler macros like the ones mentioned in http://sourceforge.net/p/predef/wiki/Compilers/. But is there a way I can look into a given compiler to find these information to find additional information? The one I use is based on arm-gcc.
Some sources:
http://www.netbsd.org/docs/pkgsrc/fixes.html#fixes.build.cpp
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/predefined-macros-platform.html
Boost has a library Predef that define a lot of macro of a lot of platform too.

Write a compiler from scratch in C [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to code a compiler in C?
How would I start writing a compiler from scratch (no Flex or Bison or Lex or Yacc) in C? I have a language that I wrote an interpreter for, and it's kind of like Forth. Sort of. It takes in symbols and interprets them one at a time, using a stack.
How would I make a compiler?
That wasn't a particularly spammy bit; just to show people the syntax and simplicity.
http://github.com/tekknolagi/StackBased
Simple!
You tokenize the input.
You build a proper representation of it, generally this is an Abstract Syntax Tree, but that is not required.
You perform any tree transformations you may require (optional).
You generate the code by walking the tree.
You link any disparate portions together (optional)
Flex and Bison help with stage 1 and 2, everything else is up to you. If you're still stuck, I suggest going through "Programming Language Pragmatics" or The Dragon Book.

Resources