Skip to content

__attribute__((constructor)) is ignored on static functions #54

Description

@ludocode
#include <stdio.h>

const char* a = "nope";

__attribute__((__constructor__)) static void foo(void) {
    a = "yep";
}

int main(void) {
    puts(a);
}

Gives compiler warning "'void foo(void)' defined but not used" and resulting binary prints "nope" under cparser 8ec1a76. Prints "yep" under GCC and Clang. Removing the keyword static fixes it.

Is cparser still maintained? There haven't been any commits in 5 months or resolved issues in over a year. It doesn't look like there's much point in logging these bugs; mostly I'm just doing it so that other people can find them in case they run into the same bug.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions