Browse Source

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 <dev@codyps.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cody P Schafer 10 years ago
parent
commit
eda7c5a20e
1 changed files with 2 additions and 1 deletions
  1. 2 1
      tools/configurator/configurator.c

+ 2 - 1
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 <sys/types.h>\n"