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
480 return 0;480 return 0;
481}481}
482 482
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
483char str_ag1[] = "b";487char str_ag1[] = "b";
484char str_ag2[] = { "b" };488char str_ag2[] = { "b" };
485/*char str_bg1[] = ("cccc"); GCC accepts this with pedantic warning, TCC not */489/*char str_bg1[] = ("cccc"); GCC accepts this with pedantic warning, TCC not */
490#ifdef CONSTANTINDEXEDSTRLIT
486char str_ag3[] = { "ab"[1], 0 };491char str_ag3[] = { "ab"[1], 0 };
487char str_ag4[2] = { "b" };
488char str_x[2] = { "xy" "z"[2], 0 };492char str_x[2] = { "xy" "z"[2], 0 };
493#endif
489char *str_ar[] = { "one", "two" };494char *str_ar[] = { "one", "two" };
490struct str_SS {unsigned char a[3], b; };495struct str_SS {unsigned char a[3], b; };
491struct str_SS str_sinit15 = { "r" };496struct str_SS str_sinit15 = { "r" };
@@ -500,12 +505,15 @@ static void string_test2() · 8 unmodified lines
500 char *pa2 = { "xyz" + 1 };505 char *pa2 = { "xyz" + 1 };
501 int i = 0;506 int i = 0;
502 struct str_SS ss = { { [0 ... 1] = 'a' }, 0 };507 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
503 puts("string_test2");512 puts("string_test2");
504 puts(str_ag1);513 puts(str_ag1);
505 puts(str_ag2);514 puts(str_ag2);
506 /*puts(str_bg1);*/515 /*puts(str_bg1);*/
507 puts(str_ag3);516 puts(str_ag3);
508 puts(str_ag4);
509 puts(str_x);517 puts(str_x);
510 puts(str_sinit15.a);518 puts(str_sinit15.a);
511 puts(str_sinit16[0].a);519 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