History

Workaround old GCC viz indexed string literals

GCCs before gcc8 didn't deal with these where constants are required.

Michael Matz committed 6 years ago

Commit 18db8da1 parent 1711eb21 file · +10 −2Browse files

Unified · Split

tests/tcctest.c+10−2
@@ -480,12 +480,17 @@ int ret(a) · 479 unmodified lines
480480 return 0;
481481 }
482482
483+#if !defined(__TINYC__) && (__GNUC__ >= 8)
484+/* Old GCCs don't regard "foo"[1] as constant, even in GNU dialect. */
485+#define CONSTANTINDEXEDSTRLIT
486+#endif
483487 char str_ag1[] = "b";
484488 char str_ag2[] = { "b" };
485489 /*char str_bg1[] = ("cccc"); GCC accepts this with pedantic warning, TCC not */
490+#ifdef CONSTANTINDEXEDSTRLIT
486491 char str_ag3[] = { "ab"[1], 0 };
487−char str_ag4[2] = { "b" };
488492 char str_x[2] = { "xy" "z"[2], 0 };
493+#endif
489494 char *str_ar[] = { "one", "two" };
490495 struct str_SS {unsigned char a[3], b; };
491496 struct str_SS str_sinit15 = { "r" };
@@ -500,12 +505,15 @@ static void string_test2() · 8 unmodified lines
500505 char *pa2 = { "xyz" + 1 };
501506 int i = 0;
502507 struct str_SS ss = { { [0 ... 1] = 'a' }, 0 };
508+#ifndef CONSTANTINDEXEDSTRLIT
509+ char str_ag3[] = { "ab"[1], 0 };
510+ char str_x[2] = { "xy" "z"[2], 0 };
511+#endif
503512 puts("string_test2");
504513 puts(str_ag1);
505514 puts(str_ag2);
506515 /*puts(str_bg1);*/
507516 puts(str_ag3);
508− puts(str_ag4);
509517 puts(str_x);
510518 puts(str_sinit15.a);
511519 puts(str_sinit16[0].a);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t