From eda7c5a20ecb045b5a0181261537bdbef6125a6d Mon Sep 17 00:00:00 2001 From: Cody P Schafer Date: Sun, 16 Aug 2015 18:54:37 -0400 Subject: [PATCH] configurator: hide type punning As for the type punning: gcc-5.1 with optimization (at least) warns about type punning in the previous example. The new usage should be exactly equivalent to the old, but just seperates the cast and deref into 2 statements. Frankly, I'm suprised gcc's type-punning analysis is so limited. Signed-off-by: Cody P Schafer Signed-off-by: Rusty Russell --- tools/configurator/configurator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index a162ee67..119404f5 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -282,7 +282,8 @@ static struct test tests[] = { "int main(int argc, char *argv[]) {\n" " char pad[sizeof(int *) * 1];\n" " strncpy(pad, argv[0], sizeof(pad));\n" - " return *(int *)(pad) == *(int *)(pad + 1);\n" + " int *x = (int *)pad, *y = (int *)(pad + 1);\n" + " return *x == *y;\n" "}\n" }, { "HAVE_UTIME", DEFINES_FUNC, NULL, NULL, "#include \n" -- 2.39.2