The identifier `char` is not mangled in C backend
MRE
char: str
char = ""
$ lpython examples/expr2.py --backend=c
expr2__tmp__generated__.c:13:8: error: expected identifier or '('
char * char = NULL;
^
expr2__tmp__generated__.c:16:23: error: expected expression
_lfortran_strcpy(&char, "", 1);
^
2 errors generated.
The command 'gcc -o expr2.out expr2__tmp__generated__.c -I /Users/thirumalai/Open_Source/lpython/src/bin/../libasr/runtime -L"/Users/thirumalai/Open_Source/lpython/src/bin/../runtime" -Wl,-rpath,"/Users/thirumalai/Open_Source/lpython/src/bin/../runtime" -llpython_runtime -lm' failed.
@Thirumalai-Shaktivel What should I replace the restricted keywords in C & C++ with?
Will renaming them LFORTRAN_RESTRICTED_keyword be ok?
Nope, I think we need to recognise the keywords and mangle them, .i.e, if we see char, we need to replace it as _xx_char_xx or __xx_char or something that is less probable to be used. For this, I think we have to handle it in the unqiue_symbol pass or the C backend itself.
See https://lfortran.zulipchat.com/#narrow/stream/311866-LPython/topic/asr-.3Ec for the discussion about this. Indeed, enhancing the mangling pass is the way to go.
I have implemented this in PR #2546. I have only implemented the mangling for the C backend; the C++ backend is still pending.
@Thirumalai-Shaktivel this issue could be closed as #2546 was merged.
I following works, so closing this
char: str
char = "c"
print (char)
$ lpython examples/expr2.py
c