Ticket Hash: | 89be88b4c27e85b7590d2da5f4b8ce6334c18a35 | |||
Title: | Variables cannot be initalized at declaration time in CC8 | |||
Status: | Closed | Type: | Code Defect | |
Severity: | Severe | Priority: | Low | |
Subsystem: | CC8 | Resolution: | Rejected | |
Last Modified: | 2019-03-29 22:52:39 | |||
Version Found In: | ||||
User Comments: | ||||
tangent added on 2017-11-16 20:40:37:
(text/x-fossil-wiki)
Variables cannot be set at declaration time. The compiler doesn't complain, but the variable does not get set as C requires. Simple test case: <pre> int main() { int i = 5; printf("i = %d\r\n", i); } </pre> I happen to get 172 here, but I expect it's just random junk on the stack at program load time. poetnerd added on 2019-01-13 15:44:24: (text/x-fossil-plain) It was initially unclear to me if this was a bug report for the cc8 cross compiler, or the native OS/8 compiler, so I did a little investigation. Because of bug a4123bb743, the test case won't compile under the cc8 cross compiler. If "int" is taken off the declaration of main, the cc8 cross compiler dutifully complains that it can't cope with the construct. It complains 3 times that we are missing a semicolon: wdc-home2:os8 wdc$ ../../../bin/cc8 idecl.c / INT I = 5; / ^ /****** MISSING SEMICOLON ****** / INT I = 5; / ^ /****** INVALID EXPRESSION ****** / INT I = 5; / ^ /****** MISSING SEMICOLON ****** Error(s) So this problem is two-fold: 1. The variable initialization feature is missing from the native OS/8 compiler. 2. No complaint comes from the compiler. Instead it generates code with undefined behavior. Root cause here is the tinyC ancestry of the native OS/8 compiler, as well as the challenge of fitting error reporting into a parser that fits into only 4K. tangent added on 2019-03-29 22:52:39: (text/x-fossil-plain) This limitation affects only the native compiler. It is [/doc/trunk/doc/cc8-manual.md#nlim|documented], and it's unlikely to be fixed due to code space limitations. |