Bug in macro function TEST(s) #s.
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.
Hello, Did you get to the end of the course first? Can you try this on the last commit and see if its still present
Thanks
I didn't finish the course yet. I found the problem when I was coding follow your video, I was afraid it was my fault, so I reexamined it by pulling the last commit, but the problem still exsists.
Terminal outputs:
george@george-virtual-machine:~/Desktop/ccc/PeachCompiler$ ./main
section .data
section .text
extern printf
global main
; main function
main:
push ebp
mov ebp, esp
lea ebx, [printf]
push ebx
pop ebx
mov dword [function_call_1], ebx
mov eax, str_2
push eax
mov eax, str_3
push eax
call [function_call_1]
add esp, 8
push eax
pop eax
push eax
add esp, 4
pop ebp
ret
section .data
function_call_1: dd 0
section .rodata
str_2: db 'h', 'e', 'l', 'l', 'o', ')', 0
str_3: db '%', 's', 10, 0
everything compiled file
/usr/bin/ld: ./test.o: warning: relocation in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
nasm -f elf32 ./test -o ./test.o && gcc -m32 ./test.o -o ./testgeorge@george-virtual-machine:~/Desktop/ccc/PeachCompiler$ ./test
hello)
But did you pull the most recent commit in the whole repository to test it against because sometimes things get fixed as we go along
Thanks
I tried it just now, the problem still persists, below is my git information, is it the lastest commit?
george@george-ubuntu:~/Desktop/gitcompiler/PeachCompiler$ git remote -v
origin https://github.com/nibblebits/PeachCompiler.git (fetch)
origin https://github.com/nibblebits/PeachCompiler.git (push)
george@george-ubuntu:~/Desktop/gitcompiler/PeachCompiler$ git pull
Already up to date.
george@george-ubuntu:~/Desktop/gitcompiler/PeachCompiler$ git log
commit 6bbbd1a9a85fdbdb7364a2ac6fb27da622566423 (HEAD -> main, origin/main, origin/HEAD)
Author: Daniel McCarthy <[email protected]>
Date: Sat May 27 12:46:25 2023 +0100
Lecture 258 - Implementing the validation of structures and unions
commit 47c7e60ea1316712571b203d333ffdb54f40f781
Author: Daniel McCarthy <[email protected]>
Date: Sat May 27 10:12:37 2023 +0100
Lecture 257 - Implementing the validation of statements
commit 34ad00e88d62d0577dfcdead5f3c5d3ed1ce242a
Author: Daniel McCarthy <[email protected]>
Date: Sat May 27 09:56:22 2023 +0100
Great thanks I will keep the issue open until the problem is solved thanks for letting me know