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.
Related
This question already has answers here:
Is there an equivalent in C for C++ templates?
(7 answers)
Closed 4 years ago.
I've previously worked with C but I'm still a major newby in general.
Currently I'm working on a little project that involves Parallel Computing and for this we are using the language Cilk+.
My objective is to implement a parallel scan pattern using Cilk+ and I've found this reference to the subject, but I don't understand half of the notations on it.
Does C have templates? I thought only C++ had them.
If yes, how do they work? I've found nothing regarding the subject.
If not, then can someone explain me what line 1 and 5 mean?
Thank you in advance!
C does not have templates. C++ does.
Line 1 is using C++ templates.
Line 5 is not standard C or C++. It is part of the Cilk Plus extension.
If this is a new project, you may way to avoid Cilk Plus. It's officially deprecated. Intel is encouraging everyone to switch to OpenMP or TBB instead.
This question already has answers here:
Disabling Warnings generated via _CRT_SECURE_NO_DEPRECATE
(10 answers)
Closed 5 years ago.
I'm currently trying to get some C code that I originally wrote for linux (gcc) to build on a win32 box.
The MSVC compiler is giving me warnings for all my printf and scanf usage suggesting I should use printf_s and scanf_s instead as a more secure alternative.
Its never nice to ignore 100's of compiler warnings, but should I in this instance?
Is there a simple workaround to fix this? Perhaps encapsulate those functions in a platform specific preprocessor directive?
You can suppress these warning by defining _CRT_SECURE_NO_DEPRECATE before the #include statements. But you should consider to use the new, secure functions.
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.
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.
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.