Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
C / CPP backends differ in argument evaluation order #8202
More info: https://forum.nim-lang.org/t/4010
This is a serious issue...
How I fixed it for me: ConsoleTVs/TFG@c3698f6#diff-ecd2a08316dc75e0142a9547a218c408
EDIT: added code to repreduce:
var current: int = 0 proc gen(): string = current.inc; $(current - 1) proc allOut(a, b, c: string) = echo a echo b echo c allOut(gen(), gen(), gen())
The issue itself seems to evaluate the arguments of functions in a different order when using c++ backend.
In my case. As the fixed link i gave, you can see how to fix it by forcing to evaluate the parameters outside the argument list. Somebosy answered that on the forum, it might help you out
Well I looked at the generated cpp code and the generated c code:
My personal opinion is that it is weird that they differ this much. But apart from that I think both are correct. I think no program should rely on the order of argument evaluation. Is the order of argument evaluation specified in Nim? Because in neither C nor Cpp it is specified. On a different C++ compiler you might get a different order of argument evaluation. I know this and I never had problems with this.
@ConsoleTVs As I said it is not just that different programming languages differ in argument evaluation, it is that different compilers differ in argument evaluation order. Try it with different backend like visual studio compiler and gcc. So I wouldn't argument that this issue is [IMPORTANT]. It wouldn't be a surprise to any programmer who comes from c or c++ that you should not rely on the order of argument evaluation. Not just because compilers might change the order at will, but also because of readability.