|
|
Log in / Subscribe / Register

My advice on implementing stuff in C:

My advice on implementing stuff in C:

Posted Oct 19, 2010 11:36 UTC (Tue) by nix (subscriber, #2304)
In reply to: My advice on implementing stuff in C: by cmccabe
Parent article: Russell: On C Library Implementation

A better alternative for short functions that do something trivial is static inline functions. You can't make something a macro unless it's just shortening something the user can do anyway, and for *that* you generally want static inlines in a header file. A decent compiler will inline them for you if appropriate.

What macros really can do that nothing else can is anything involving stringization or token pasting, e.g. filling up a structure statically with information describing other C identifiers (fields in some other structure, that sort of thing). Thanks to stringization you can fill in the *name* of the identifier and its size without worrying about skew.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds