Back to libsm overview

libsm : C Language Portability Macros

$Id: cdefs.html,v 1.2 2000/12/07 17:33:09 dmoen Exp $


The header file <sm/cdefs.h> defines portable interfaces to non-portable features of various C compilers. It also assists you in writing C header files that are compatible with C++.
This macro is used to write portable function prototypes. For example,
int foo __P((int));
This macro concatenates two tokens x and y, forming a single token xy. Warning: make sure there is no white space around the arguments x and y.

This macro converts the token sequence x into a string literal.

These macros are used to write C header files that are compatible with C++ compilers. Put __BEGIN_DECLS before the first function or variable declaration in your header file, and put __END_DECLS after the last function or variable declaration.

const, signed, volatile
For pre-ANSI C compilers, const, signed and volatile are defined as empty macros. This means you can use these keywords without introducing portability problems.

This macro modifies a prototype of a function that does not return to its caller. With some versions of gcc, this will result in slightly better code, and can suppress some useless warnings produced by gcc -Wall. For example,
SM_DEAD(void exit __P((int)));
This macro modifies a definition of an unused local variable, global variable or function parameter in order to suppress compiler warnings. Examples:
SM_UNUSED(static const char Id[]) = "@(#)$Id: cdefs.html,v 1.2 2000/12/07 17:33:09 dmoen Exp $";
	SM_UNUSED(int x);
	SM_UNUSED(int y) = 0;
	return 0;
bar(SM_UNUSED(int x))
	return 0;