-
Notifications
You must be signed in to change notification settings - Fork 26
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
Check -W -Wall -ansi #3
Comments
Turned on some (fdf29d5), disabled others so it still compiles without noise. Should probably check the clobbering warning. |
While I think it makes sense for es to be built in "native mode" for practical use, I also think that for testing/development purposes, it makes sense to add a Current blockers to successfully building with those two flags defined:
We could even add
This strict-mode es could be used in the CircleCI tests to help prevent easy-to-miss bugs/unportabilities slipping in. |
That's reasonable, and it definitely would help catch some simple standards-compliance issues.
Perhaps Similarly, the
Storing a Doing that also eliminates an issue with C's "undefined behavior". There's also the fact that glibc doesn't define
That's definitely my oopsie.
This is required by POSIX.1-2008, but not by POSIX.1-2001 unless the XSI option is supported; see the Rationale for POSIX.1-2001 If this is a problem, maybe run the preprocessor on all C files to generate an array of primitives since the number of primitives is relatively small (currently maxed out 54). Sample implementation (includes a fixed |
Wow, that's sophisticated. I was just thinking of wrapping the primitive functions inside a small struct. :) #include <stdio.h>
int prim_func(int i) { return i + 1; }
int lookatthevoid(void *p) { printf("%d\n", sizeof(p)); }
int main(int c, char **argv) {
struct { int (*prim)(int); } p;
/* not allowed with -ansi -pedantic */
lookatthevoid((void *)&prim_func);
p.prim = prim_func;
/* allowed with -ansi -pedantic */
lookatthevoid((void *)&p);
} |
Here's my quick-and-dirty diff for diff --git a/prim.c b/prim.c
index 13a66ae..74d7866 100644
--- a/prim.c
+++ b/prim.c
@@ -6,11 +6,11 @@
static Dict *prims;
extern List *prim(char *s, List *list, Binding *binding, int evalflags) {
- List *(*p)(List *, Binding *, int);
- p = (List *(*)(List *, Binding *, int)) dictget(prims, s);
+ Prim *p;
+ p = (Prim *) dictget(prims, s);
if (p == NULL)
fail("es:prim", "unknown primitive: %s", s);
- return (*p)(list, binding, evalflags);
+ return (p->prim)(list, binding, evalflags);
}
static char *list_prefix;
diff --git a/prim.h b/prim.h
index 68e346b..9c2f249 100644
--- a/prim.h
+++ b/prim.h
@@ -1,13 +1,19 @@
/* prim.h -- definitions for es primitives ($Revision: 1.1.1.1 $) */
+typedef struct { List *(*prim)(List *, Binding *, int); } Prim;
+
#define PRIM(name) static List *CONCAT(prim_,name)( \
List UNUSED *list, Binding UNUSED *binding, int UNUSED evalflags \
)
-#define X(name) (primdict = dictput( \
- primdict, \
- STRING(name), \
- (void *) CONCAT(prim_,name) \
- ))
+
+#define X(name) STMT( \
+ static Prim CONCAT(prim_struct_,name) = { CONCAT(prim_,name) }; \
+ primdict = dictput( \
+ primdict, \
+ STRING(name), \
+ (void *) &CONCAT(prim_struct_,name) \
+ ) \
+ )
extern Dict *initprims_controlflow(Dict *primdict); /* prim-ctl.c */
extern Dict *initprims_io(Dict *primdict); /* prim-io.c */ |
That...makes more sense and is a lot simpler to maintain. |
Just because we can.
The text was updated successfully, but these errors were encountered: