Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize a struct with a previously declared const struct. #1375

Open
negge opened this issue Jan 16, 2025 · 2 comments
Open

Cannot initialize a struct with a previously declared const struct. #1375

negge opened this issue Jan 16, 2025 · 2 comments

Comments

@negge
Copy link

negge commented Jan 16, 2025

Initializing a struct is valid C99 but does not work with WATCOM. For example,

typedef struct Point2D Point2D;

struct Point2D {
  float x;
  float y;
};

const Point2D ZERO = { 0, 0 };

Point2D pos = ZERO;

void main() {
  pos.x += 1;
}

This builds fine with gcc and clang, but building with wcc I get the following errors:

$ wcc test.c
Open Watcom C x86 16-bit Optimizing Compiler
Version 2.0 beta Jun  1 2024 01:58:31 (32-bit)
Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See https://github.com/open-watcom/open-watcom-v2#readme for details.
test.c(10): Error! E1070: Data for aggregate type must be enclosed in curly braces
test.c(10): Error! E1054: Expression must be constant
test.c(10): Error! E1009: Expecting ',' but found ';'
test.c(12): Error! E1063: Missing operand
test.c(12): Error! E1054: Expression must be constant
test.c(12): Error! E1009: Expecting ';' but found 'void'
test.c: 15 lines, 0 warnings, 6 errors

This has many peculiar error messages. E1054 is odd because the expression on line 10 is constant but I think that is a result of E1070 happening first.

@jmalak
Copy link
Member

jmalak commented Jan 16, 2025

You are in C89 mode.

@negge
Copy link
Author

negge commented Jan 17, 2025

Are you sure that is it? Setting C99 mode gives the same errors:

$ wcc -zastd=c99 test.c
Open Watcom C x86 16-bit Optimizing Compiler
Version 2.0 beta Jun  1 2024 01:58:31 (32-bit)
Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See https://github.com/open-watcom/open-watcom-v2#readme for details.
test.c(10): Error! E1070: Data for aggregate type must be enclosed in curly braces
test.c(10): Error! E1054: Expression must be constant
test.c(10): Error! E1009: Expecting ',' but found ';'
test.c(12): Error! E1063: Missing operand
test.c(12): Error! E1054: Expression must be constant
test.c(12): Error! E1009: Expecting ';' but found 'void'
test.c: 15 lines, 0 warnings, 6 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants