3 ms·
When I worked on my own language that links to libc, it turned out that MSVC has the standard streams (stdin etc) defined as macros. That's really annoying sinc
by jstimpfle 7y ago
When I worked on my own language that links to libc, it turned out that MSVC has the standard streams (stdin etc) defined as macros. That's really annoying since that means one has to write a C wrapper function to expose these streams. It might have been possible to avoid these macros, but that probably puts some constraints on the allocation done inside libc.
On the other hand, there are some things you simply cannot do without macros. I usually use function-like macros to forward to other functions with additional arguments (like __FILE__, or #arg, sizeof(arg)) which is extremely convenient and allows to cut out a lot of error-prone boilerplate.
From a different language, you can still call the function that is being forwarded to. Now try doing that with C++ templates or whatever...
- jmgao 7y agoHilariously, the C standard requires this. C11 7.21.1.3: "The macros are [...] stderr, stdin, stdout which are expressions of type ‘‘pointer to FILE’’ that point to the FILE objects associated, respectively, with the standard error, input, and output streams."
- ainar-g 7y agoYou probably meant to point to 7.21.1.3, not 7.21.3. I had to look it up myself, and sure enough, that's true[1]. The C Standard is a magical document indeed. [1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
- jmgao 7y agoOops, yes, thanks!