Here is my background:
I am a college student and have some assignment that only permitted language is C.
And every single task must only have one single c file which contains main, I don't want C, so I try nim.
And here are my steps:
nim c -c -nimcache:. hello.nim
Get-Content -path .\* -Filter *.nim.c | Out-File my.c #shell is ok, my.c contains all c file
Sadly, Some problem appear
All I want is to compile a nim single file to a single c file that only depends standard c header and lib
Does anyone offer a help? Does nim compiler or correlated toolchain have a way to deal it?
i can't help with the multiple definitions, but you dont have to manually include the header, you can use gcc -E -I/path/to/nim/lib @mmain.nim.c and it'll output the preprocessed C, with the includes pasted in. i think this is a hard problem, and unlikely to have a good solution, as your needs are a bit obscure, but there are some tools online to merge c files for programming contests maybe one of those will help.
I fully support you spending many hours trying to get this to work rather than focusing on your studies or learning C.
I fully support you spending many hours trying to get this to work rather than focusing on your studies or learning C.
LOL to the 9th power. :-)
I just tried out to see if I could do this, and I actually did it with https://github.com/goblint/cil after patching nimbase.h.
But I doubt that it'll be useful, since for a hello world (full debug) I got 10k lines of C code, and when compiled with -d:danger --gc:arc -d:useMalloc I got 2.6k lines - check out the resulting C file here
A big problem with C pointer syntax is that users space things misleadingly. For example, they will write char* s; instead of char *s; - as misleading as a+b * c. Zero spaces would be better than fighting with spacing the "single expression sub-syntax economy" of declarator sub-syntax.
This even contacts the syntactic whitespace debate (and Nim used to have strong spaces!) against C/C++ (but maybe not other langs) having it not matter. Not mattering lets people confuse themselves so much that they never learn an important subsyntax.
@xigoi I encounter with the same issue. <stdio.h> declares ___errno_location, _stdout, _stderr.
Certainly, you cannot include <stdio.h> which have a conflict
I tried with AppleClang-12 and GCC-10, both miss these three
with "-v" verbose output, I notice the linking command is exactly the same, so is compiling command
By carefully inspection, I think that might because FILE definition in C file and <stdio.h> is different, but I'm not sure about it
My mistake, I made an unclear statement about it, which I think is unrelated information.
It is a pure self-made online-judge website, which only support C( C99? I'm not sure).
I think you can literally use a lot of language learning algorithm. As far as raw pointer, I'm on your side