Back to libsm overview

# libsm : C Language Portability Macros

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

## Description

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++.

`__P(parameterlist)`
  This macro is used to write portable function prototypes. For example,

  >     int foo __P((int));

`__CONCAT(x,y)`
  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.

`__STRING(x)`
  This macro converts the token sequence x into a string literal.

`__BEGIN_DECLS, __END_DECLS`
  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.

`SM_DEAD(function_declaration)`
  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)));

`SM_UNUSED(variable_declaration)`
  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 $";
  >     void
  >     foo(x)
  >     	SM_UNUSED(int x);
  >     {
  >     	SM_UNUSED(int y) = 0;
  >     	return 0;
  >     }
  >     void
  >     bar(SM_UNUSED(int x))
  >     {
  >     	return 0;
  >     }