Skip to content

multi-character constants

github logo ・1 min read  

Some time ago I encountered another feature of C99 standard, that I wasn't aware yet. So called multi-character constants.

In a code it may look like so:

    const uint32_t png_ihdr = 'IHDR';

or even sneakier (as enums are usually implemented as ints):

        M_BUTTON_CLICKED = 'btcl'

The standard says: "The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined."

This feature is very useful to define Atoms having a value actually meaningful to humans.

twitter logo DISCUSS
Classic DEV Post from Jul 30 '19

Save the planet, clean your mailbox

Tomasz Sterna profile image
I am a coder. I do hard-core C, Embedded JavaScript, C++/Qt/QML, Rust GameDev, Reason React, XMPP. Preferably Open Source.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❤️