Mercurial > projects > ldc
annotate dmd/root/gnuc.c @ 1499:df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
The idea is to separate the notion of const from 'this variable can always be
replaced with its initializer' in the frontend. To do that, I introduced
Declaration::isSameAsInitializer, which is overridden in VarDeclaration to
return false for constants that have a struct literal initializer.
So
{{{
const S s = S(5);
void foo() { auto ps = &s; }
// is no longer replaced by
void foo() { auto ps = &(S(5)); }
}}}
To make taking the address of a struct constant with a struct-initializer
outside of function scope possible, I made sure that AddrExp::optimize doesn't
try to run the argument's optimization with WANTinterpret - that'd again
replace the constant with a struct literal temporary.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 14 Jun 2009 19:49:58 +0200 |
parents | 1853dcd9b944 |
children |
rev | line source |
---|---|
1 | 1 |
2 // Put functions in here missing from gnu C | |
3 | |
4 #include "gnuc.h" | |
5 | |
6 int memicmp(const char *s1, const char *s2, int n) | |
7 { | |
8 int result = 0; | |
9 | |
10 for (int i = 0; i < n; i++) | |
11 { char c1 = s1[i]; | |
12 char c2 = s2[i]; | |
13 | |
14 result = c1 - c2; | |
15 if (result) | |
16 { | |
17 if ('A' <= c1 && c1 <= 'Z') | |
18 c1 += 'a' - 'A'; | |
19 if ('A' <= c2 && c2 <= 'Z') | |
20 c2 += 'a' - 'A'; | |
21 result = c1 - c2; | |
22 if (result) | |
23 break; | |
24 } | |
25 } | |
26 return result; | |
27 } | |
28 | |
29 int stricmp(const char *s1, const char *s2) | |
30 { | |
31 int result = 0; | |
32 | |
33 for (;;) | |
34 { char c1 = *s1; | |
35 char c2 = *s2; | |
36 | |
37 result = c1 - c2; | |
38 if (result) | |
39 { | |
40 if ('A' <= c1 && c1 <= 'Z') | |
41 c1 += 'a' - 'A'; | |
42 if ('A' <= c2 && c2 <= 'Z') | |
43 c2 += 'a' - 'A'; | |
44 result = c1 - c2; | |
45 if (result) | |
46 break; | |
47 } | |
48 if (!c1) | |
49 break; | |
50 s1++; | |
51 s2++; | |
52 } | |
53 return result; | |
54 } | |
55 |