Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tommath_c89.h versus other solutions for backward compatibility with <C99 #526

Open
assarbad opened this issue Feb 13, 2022 · 2 comments
Open

Comments

@assarbad
Copy link

The number of makefiles in this project is staggering, but in any case the issue I addressed in #525 for MSVC doesn't seem to be limited to MSVC. Seeing that there is a tommath_c89.h in the source tree, I was wondering if a more generalized approach for any C below C99 wouldn't be the better option at all. In the current draft pull request the header is pretty complete, but has preprocessor conditions which will make it fail on non-MSVC compilers.

Arguably it could be tested on other old compilers (ancient Watcom comes to mind) and the switching could be done based on checking against the standard version, e.g.:

#if (__STDC_VERSION__ < 199901L)
#include <tommath_c89.h> /* an extended version of the current one */
#else
#include <stdint.h>
#include <stdbool.h>
#endif

(or invert the condition order, I don't care)

Either way this would improve the robustness and have all compilers benefit from the C89 compatibility, not just builds done with that makefile where some sed command creates an illusion of compatibility by changing the source files prior to a build (something that in my book is a big no no when building third-party code).


I would also recommend renaming the makefile to GNUmakefile and then consolidating its contents. E.g. for the assignment to OBJECTS it could use something akin to what the pre_gen (amalgamation) target has:

SOURCES:=$(wildcard *mp_*.c)
OBJECTS:=$(SOURCES:.c=.o)

Rationale: if you already have a special makefile for GNU make it makes sense to make this explicit and limit its scope to GNU make. A makefile by the name GNUmakefile will be picked up first by GNU make (it has several names hardcoded), even before makefile. So it could in fact work to rename the current makefile to GNUmakefile then rename the current makefile.unix to makefile. The behavior should be the same, except that on BSD you no longer need to specify the file name.

For the most part when using GNU make I'd also recommend immediate assignments (:=) as opposed to lazy ones (=).

@assarbad assarbad changed the title tommath_C89.h versus other solutions for backward compatibility with <C99 tommath_c89.h versus other solutions for backward compatibility with <C99 Feb 13, 2022
@sjaeckel
Copy link
Member

C.f. #525 (comment)

@assarbad
Copy link
Author

assarbad commented Feb 13, 2022

You beat me by it by ~10 minutes. But I hadn't even seen the notification or noticed your update.

Either way, what do you think about the proposals from this ticket, @sjaeckel ? (I'll be patient. Saw the remark on the other ticket.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants