Skip to content

Commit f546069

Browse files
committed
fixes in c89 (hide "edit mode")
1 parent 968d3a0 commit f546069

File tree

15 files changed

+8125
-7713
lines changed

15 files changed

+8125
-7713
lines changed

manual.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
## Intro
3-
Cake works as an extension for MSVC on Windows and as an extension for GCC on Linux. This approach makes Cake useful in real and existing programs.
3+
Cake works as an extension for MSVC on Windows and as an extension for GCC on Linux.
4+
This approach makes Cake useful in real and existing programs.
45

56
When applicable, Cake uses the same command line options of MSVC and GCC.
67

@@ -9,7 +10,6 @@ For static analyzer concepts of ownership and nullable pointers visit [ownershi
910

1011
## Include directories
1112

12-
1313
On Windows, Cake can be used on the command line similarly to MSVC.
1414
Cake reads the `INCLUDE` variable, the same variable used by MSVC to locate the include directories.
1515

@@ -142,6 +142,8 @@ Format input (format before language conversion)
142142
#### -fo
143143
Format output (format after language conversion, result parsed again)
144144

145+
#### -ir
146+
Generates C89 code
145147

146148
#### -Wname -Wno-name (same as GCC)
147149
Enables or disable warnings.
@@ -327,8 +329,10 @@ Becomes (not implemented)
327329
```c
328330
struct s {
329331
int n;
330-
double d[]; //?
332+
double d[1];
331333
};
334+
335+
//TODO sizeof
332336
```
333337

334338

@@ -358,17 +362,15 @@ int main()
358362

359363
```
360364
361-
`static` is removed when target is < c99.
362-
363-
Cakes verifies that the argument is an array of with equal or more elements.
364-
365-
Cakes extend this check for arrays without static as well.
365+
Cake verifies that the argument is an array with at
366+
least the specified number of elements.
367+
It extends this check to arrays without a static size as well.
366368
367369
### C99 Complex and imaginary support
368370
Not implemented
369371
370372
### C99 Universal character names (\u and \U)
371-
TODO
373+
Not implemented
372374
373375
### C99 Hexadecimal floating constants
374376
@@ -382,13 +384,12 @@ Becomes in C89
382384
double d = 2.000000;
383385
```
384386

385-
Cake converts the hexadecimal floating to decimal
386-
floating point using strtod then snprintf.
387-
That means this conversion is not precise.
387+
Cake converts hexadecimal floating-point values to decimal floating-point
388+
representation using strtod followed by snprintf.
389+
This conversion may introduce precision loss.
388390

389391
### C99 Compound literals
390392

391-
392393
```c
393394
struct s {
394395
int i;
@@ -404,7 +405,7 @@ int f(void) {
404405
}
405406
```
406407
407-
Becomes in C89 (not implemented yet)
408+
Becomes in C89
408409
409410
```c
410411
struct s {
@@ -420,6 +421,7 @@ int f(void) {
420421
return p == q && q -> i == 1;
421422
}
422423
```
424+
423425
N716
424426
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n716.htm
425427

@@ -437,7 +439,7 @@ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n716.htm
437439

438440
```
439441
440-
Becomes C89 (not implemented yet)
442+
Becomes C89
441443
442444
```c
443445
int main()
@@ -555,7 +557,7 @@ When compiling to versions < C11 \_Static\_Assert is removed.
555557
556558
### C11 Anonymous structures and unions
557559
558-
It is implemented, however the conversion to C99, C89 was not implemented.
560+
It is implemented, however the conversion to C99, C89 was not implemented yet.
559561
560562
```c
561563
struct v {
@@ -572,8 +574,6 @@ int main(){
572574
}
573575
```
574576

575-
I think a possible alternative to convert to C89,C99 is insert a name.
576-
577577

578578
### C11 \_Noreturn
579579

src/expressions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ struct expression* _Owner _Opt character_constant_expression(struct parser_ctx*
543543
p_expression_node->expression_type = PRIMARY_EXPRESSION_CHAR_LITERAL;
544544
p_expression_node->first_token = ctx->current;
545545
p_expression_node->last_token = p_expression_node->first_token;
546-
p_expression_node->type.attributes_flags |= CAKE_HIDDEN_ATTRIBUTE_LIKE_CHAR;
546+
p_expression_node->type.attributes_flags |= CAKE_HIDDEN_ATTRIBUTE_INT_LIKE_CHAR;
547547
p_expression_node->type.category = TYPE_CATEGORY_ITSELF;
548548

549549
const unsigned char* _Opt p = (const unsigned char*)ctx->current->lexeme;
@@ -580,7 +580,7 @@ struct expression* _Owner _Opt character_constant_expression(struct parser_ctx*
580580
compiler_diagnostic_message(C_CHARACTER_NOT_ENCODABLE_IN_A_SINGLE_CODE_UNIT, ctx, ctx->current, NULL, "character not encodable in a single code unit.");
581581
}
582582

583-
p_expression_node->object = object_make_wchar_t((wchar_t)c);//, ctx->evaluation_is_disabled);
583+
p_expression_node->object = object_make_unsigned_char((unsigned char)c);//, ctx->evaluation_is_disabled);
584584
}
585585
else if (p[0] == 'u')
586586
{

src/file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
enum X : short {
2-
A
2+
A,
3+
B
34
};
45

56
int main() {
6-
enum X x = A;
7-
}
8-
7+
enum X x = B;
8+
}
99

0 commit comments

Comments
 (0)