You are not logged in.

#1 2010-08-28 15:14:33

Berticus
Member
Registered: 2008-06-11
Posts: 731

Beside preprocessor directives, what does # mean in C?

I'm looking through the FFmpeg source code, and here's an example of what they're doing:

#define REGISTER_MUXER(X,x) { \
    extern AVOutputFormat x##_muxer; \
    if(CONFIG_##X##_MUXER) av_register_output_format(&x##_muxer); }

#define REGISTER_DEMUXER(X,x) { \
    extern AVInputFormat x##_demuxer; \
    if(CONFIG_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }

#define REGISTER_MUXDEMUX(X,x)  REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)

#define REGISTER_PROTOCOL(X,x) { \
    extern URLProtocol x##_protocol; \
    if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&x##_protocol, sizeof(x##_protocol)); }

x##_muxer, x##_demuxer, and x##_protocol don't look like they should be valid variable names. So why are they allowed here?

Offline

#2 2010-08-28 15:39:04

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Beside preprocessor directives, what does # mean in C?

It's valid preprocessor. the ## operator does concatenation.

http://www.iso-9899.info/wiki/Snippets#Preprocessor

Offline

Board footer

Powered by FluxBB