5 ms·
For adapting code to different versions of libraries for one thing: #if defined(__SunOS) presult = getprotobyname_r(proto,&result,tmp,sizeof(tmp));
by spc476 2y ago
For adapting code to different versions of libraries for one thing:
#if defined(__SunOS)
presult = getprotobyname_r(proto,&result,tmp,sizeof(tmp));
if (presult == NULL)
return luaL_error(L,"protocol: %s",strerror(errno));
#elif defined(__linux__)
if (getprotobyname_r(proto,&result,tmp,sizeof(tmp),&presult) != 0)
return luaL_error(L,"protocol: %s",strerror(errno));
#else
presult = getprotobyname(proto);
if (presult == NULL)
return luaL_error(L,"protocol: %s",strerror(errno));
result = *presult;
#endif
The sometimes annoyingly small differences between platforms.
- lerno 2y agoOh, I think you missed something then: There is both `$if` and `$switch` compile time statements for this: https://c3-lang.org/generic-programming/compiletime/#if-and-switch https://c3-lang.org/generic-programming/compiletime/#if-and-... At the top level and `@if` attribute is used to achieve the same thing: https://c3-lang.org/language-common/attributes/#if https://c3-lang.org/language-common/attributes/#if
- owlstuffing 2y agoAh. The top-level lang description claims “No preprocessor”, but my definition of that word doesn’t appear to be the same as yours :/
- lerno 2y agoThe difference here is that a preprocessor runs before parsing and semantic analysis. In C3 compile time if runs in the analysis step, so after parsing. So the macros and compile time execution occurs after parsing in C3, but in C everything happens at lexing, before the code is parsed.
- owlstuffing 2y agoThat strategy will backfire when the grammar changes in a later release. A pre-parse step is necessary for code that targets different compiler releases.
- lerno 2y agoNow I'm confused, what do you mean? What grammar changes?
- owlstuffing 2y agoImagine v2.0 introduces a new feature that requires a parser change—one that v1.0 wouldn't be able to parse. $if $defined(C3_V2_PLUS): // new feature fn f = \ -> foo(); // this won't parse in v1.0 $else Callback f = ...; $endif This is also an issue if a future version of C3 introduces language level support, allowing newer compilers to compile code as if it were written for an earlier version. While this approach works well when teams standardize on a specific version’s feature set, they may still want to take advantage of performance improvements in the latest compiler. That said, this is a niche case and not something I’d consider a dealbreaker.
- lerno 2y agoAh, that is indeed true. However, the plan is to have the language fixed at 1.0, only updating stdlib and tooling after that.
- owlstuffing 2y agoWell, if your language gains traction that plan may not succeed. For your sake, I hope that's the case :)
- lerno 2y agoI know it’s hard.