Skip to content

Provide version information in in preprocessor #282

@nemequ

Description

@nemequ

I'd like to add support for CompCert to Hedley, but AFAICT there is no way to tell from the preprocessor which version of CompCert is in use, so there is no way to tell when certain features can be enabled.

For example, it looks like noinline was added with version 3.2, so if I'd like to be able to do something like

#if defined(__COMPCERT__) && (__COMPCERT__ >= 30200)
#  define HEDLEY_NO_INLINE __attribute((noinline))
#else
#  define HEDLEY_NO_INLINE
#endif

It looks like this would basically just require something like

diff --git a/driver/Frontend.ml b/driver/Frontend.ml
index 88b47854..30d78592 100644
--- a/driver/Frontend.ml
+++ b/driver/Frontend.ml
@@ -19,7 +19,7 @@ open Driveraux
 
 let predefined_macros =
   [
-    "-D__COMPCERT__";
+    "-D__COMPCERT__=30500";
     "-U__STDC_IEC_559_COMPLEX__";
     "-D__STDC_NO_ATOMICS__";
     "-D__STDC_NO_COMPLEX__";

But obviously the version number shouldn't be hard-coded, and I'm not sure where to get it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions