Skip to content

Bug in macro function TEST(s) #s. #10

Description

@zzdmfk

C code:

#define TEST(s) #s

int printf(const char* str, ...);

int main()
{
   printf("%s\n", TEST(hello));
   return 0;
}

When I ran the above code, it outputted:

hello)

A right bracket was appended to the string, so I modified the function nextc() in lexer.c to:

static char nextc()
{
    char c = lex_process->functions->next_char(lex_process);

    if(lex_is_in_expression())
    {
        buffer_write(lex_process->parentheses_buffer, c);
        if(lex_process->argument_string_buffer)
        {
            if(c != ')') //I only added this if statement before buffer_write, I don't know if it is ok or not
                buffer_write(lex_process->argument_string_buffer, c);
        }
    }

    lex_process->pos.col += 1;
    if (c == '\n')
    {
        lex_process->pos.line += 1;
        lex_process->pos.col = 1;
    }

    return c;
}

It ouputted correctly, but I am not sure it would affects other functionalities or not.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions