Skip to content

EVAL(...) not working #226

Open
Open

Description

@ltqusst

following macro expanded as HELLO () while it should be "Hello World".
this piece of code is taken from http://saadahmad.ca/cc-preprocessor-metaprogramming-macro-basicsrules/

#define EMPTY() // This MACRO doesn't do anything
#define EVAL(...) __VA_ARGS__ // This is a simple identity macro
#define HELLO() "Hello World"

EVAL ( HELLO EMPTY() () ) 

Activity

  1. firewave commented on Jul 3, 2025

    @firewave
    Collaborator

    gcc -E

    # 0 "a.cpp"
    # 0 "<built-in>"
    # 0 "<command-line>"
    # 1 "/usr/include/stdc-predef.h" 1 3 4
    # 0 "<command-line>" 2
    # 1 "a.cpp"
    
    
    
    
    "Hello World"
    

    Current output:

    1:
    2: 
    3: 
    4: 
    5: HELLO ( )
    
  2. chrchr-github commented on Oct 6, 2026

    @chrchr-github
    Contributor

    Variation from https://trac.cppcheck.net/ticket/15083:

    #define ID(x) x
    #define EXPAND(...) __VA_ARGS__
    #define DO_NOTHING(_warn)
    #define PROCESS(...) EXPAND(ID(DO_NOTHING)(__VA_ARGS__))
    
    PROCESS(1 2)

    Expected:

    Actual:

    DO_NOTHING  ( 1 2  )
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions