Skip to content

Failed to link to variables first declared as extern then defined #59

@mingodad

Description

@mingodad

When trying to run https://github.com/Kray-G/kcs/blob/master/utility/myacc.c with kcs it generates garbage due to this declarations:

kcs/utility/myacc.c

Lines 1140 to 1142 in c2d116f

getgram()
{
extern char *retcode;

kcs/utility/myacc.c

Lines 1284 to 1286 in c2d116f

codeout()
{
extern char *code0[], *code1[];

That are then defined later on in the same file:

kcs/utility/myacc.c

Lines 1394 to 1396 in c2d116f

char *retcode = "\t\t" SMYY "val = ps[1].val; return 0;";
char *code0[] = {

If we move the definitions before it's use then I could get it to run:

kcs utility/myacc.c -v kcsrt/libsrc/kcs/json.y
uname -a
Linux XXXXX 5.4.0-137-generic #154~18.04.1-Ubuntu SMP Tue Jan 10 16:58:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Notice that the latest lacc can build an executable that runs as expected without need to reorder the variable definitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions