Skip to content

__func__ cannot share addresses with string literals in C #149749

@Halalaluyafail3

Description

@Halalaluyafail3

The following program demonstrates this issue:

#include<stdio.h>
int main(){
    static const char X[]="main";
    printf("%i\n",__func__=="main");
    printf("%i\n",X=="main");
}

Clang prints 1 then 0 with this program, when it should print 0 then 0.

The identifier __func__ shall be implicitly declared by the translator as if, immediately following
the opening brace of each function definition, the declaration

static const char __func__[] = "function-name";

appeared, where function-name is the name of the lexically-enclosing function.

Section 6.4.2.2 "Predefined identifiers" Paragraph 1 ISO/IEC 9899:2024

Unlike C++, C doesn't say that __func__ can share addresses with string literals so __func__=="main" should be zero for the same reason that X=="main" is zero.

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