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

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.

Related

Cross Platform usage of printf_s and scanf_s functions - C (linux/win32) [duplicate]

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.

Is there a way to get the macro value for a given library [duplicate]

This question already has answers here:
How to embed version information into shared library and binary?
(4 answers)
Closed 6 years ago.
I have situation as below:
#define CONSTANT 123
foo()
{
...
}
Using the above code, after creating the library lets say test.so, how can get to know the CONSTANT macro value from the library? Is there any way?
You can define the constant in a header file and supply that header with the library.
There are ways to do that:
Define the constant in a header file to the library and distribute it with the library
Make the library some form of open source
Write a dedicated get_constant function that returns the value
Its worth noting that Macros are always sheer text replacement. So after compile time you won't even know they were there.

How to find, from which include file a C preprocessor definition was taken? [duplicate]

This question already has answers here:
How to know (in GCC) when given macro/preprocessor symbol gets declared?
(6 answers)
Closed 7 years ago.
How can I find the include file, from which a certain preprocessor definition was found by GCC?
In a successfully compiling C file, I have a strange macro which I do not understand. For a start, I want to see the file where it comes from. The include hierarchy is very deep; is there an easy way to find the source of the macro?
A wider question has been asked, but the answers tell how to find the definition itself, not its source file.
redefine it before including anything else, the compiler will complain about a redefinition when it encounters it in your header hierachy:
#define MY_PROBLEMATIC_MACRO
#include <the_header.h>
/* code */

How to find definition of library functions in C [duplicate]

This question already has answers here:
Where are the functions in the C standard library defined?
(5 answers)
Closed 7 years ago.
Functions like printf() , scanf() , memset() , puts() etc have their declaration in header files but is there any mechanism to see the definition of these function..?
This might not be a new question but i could not find the appropriate solution for this.
Find your compilers include path (e.g. GCC solution)
Search for the header you are interested in (e.g. printf should be in stdio.h or more likely another header included by stdio.h)
Correctly configured, some IDEs will help you with that, e.g. Eclipse
The method has its limits though, because at some point the include files will get less and less Standard-C, but more and more compiler dependent. The C-standard does not prescribe the contents of standard headers. It merely states that if you write #include <stdio.h>, you can use printf(). That does not necessarily mean that stdio.h has some form you might expect.

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

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.

Resources