Last change
on this file since 66286aa was
eb7586e,
checked in by JiadaL <j82liang@…>, 6 months ago
|
- Change return value of typed Enum in null context: they now return the position. Therefore, printf with enumeration value will no longer be supported. 2. sout now will return the enumeration value. So sout | enumValue will print what we expect. 3. Provide enum.hfa, which contains traits that related to enum. 4. Implement functions declare in enum.hfa for enum types, so enum type fulfill the traits. Known defeat: error if we use the enum traits on enum types. They work but c compiler gives an warning
|
-
Property mode set to
100644
|
File size:
1015 bytes
|
Rev | Line | |
---|
[c17dc80] | 1 | #include <fstream.hfa> |
---|
| 2 | #include <stdlib.hfa> |
---|
| 3 | #include <stdio.h> |
---|
| 4 | |
---|
| 5 | enum(char *) Colour { |
---|
| 6 | Red = "red", Green = "green", Blue = "blue" |
---|
| 7 | }; |
---|
| 8 | |
---|
| 9 | // enum( signed char ) srgb { Red = -1, Green = 0, Blue = 1 }; |
---|
| 10 | |
---|
| 11 | enum Plain { A, B, C = 10 }; |
---|
| 12 | |
---|
| 13 | int main () { |
---|
[eb7586e] | 14 | Colour fishy; |
---|
| 15 | fishy = Colour.Green; |
---|
| 16 | fishy; |
---|
[c17dc80] | 17 | Colour c2 = fishy; |
---|
[eb7586e] | 18 | |
---|
| 19 | sout | "Compile Time: blue value: " | valueE(Colour.Blue) | ", position: " | posE(Colour.Blue) | ", label: " | labelE(Colour.Blue) | ", default return value: " | Colour.Blue; |
---|
| 20 | sout | "Runtime: fishy value: " | valueE(fishy) | ", position: " | posE(fishy) | ", label: " | labelE(fishy) | ", default return value: " | fishy; |
---|
| 21 | sout | "Runtime: C2 value: " | valueE(c2) | ", position: " | posE(c2) | ", label: " | labelE(c2) | ", default return value: " | c2; |
---|
[c17dc80] | 22 | Colour.Red; |
---|
| 23 | char * ao = Colour.Red; |
---|
| 24 | char * ko = fishy; |
---|
| 25 | printf( "ao is %s\n", ao ); |
---|
| 26 | printf( "ko is %s\n", ko ); |
---|
| 27 | |
---|
| 28 | printf( "%d, %d, %d, \n", A, B, C ); |
---|
| 29 | Plain a = B; |
---|
| 30 | printf( "%d \n", a ); |
---|
[eb7586e] | 31 | |
---|
[c17dc80] | 32 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.