Skip to content

Allow multiple declarators in a declaration#5595

Open
ChrisDodd wants to merge 1 commit into
p4lang:mainfrom
ChrisDodd:cdodd-decls
Open

Allow multiple declarators in a declaration#5595
ChrisDodd wants to merge 1 commit into
p4lang:mainfrom
ChrisDodd:cdodd-decls

Conversation

@ChrisDodd

Copy link
Copy Markdown
Contributor

Some people consider multiple declarators in a declaration as one of the big mistakes of C, and think they should never be used. Some coding standards require that every variable be declared in a separate declaration, as P4 currently requires.

Other people coming to P4 from C or C++ are annoyed by this restriction, and try to write code with multiple declarators.

This change allows such declarations as an extension, and can warn about them as a non-standard extension.

@asl

asl commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Can we have testcase for this, please?

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Apr 21, 2026
@ChrisDodd

Copy link
Copy Markdown
Contributor Author

Can we have testcase for this, please?

One (small) testcase added.

@fruffy

fruffy commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Seems like it should be a command-line option to toggle these extensions on/off.

@ChrisDodd

Copy link
Copy Markdown
Contributor Author

Seems like it should be a command-line option to toggle these extensions on/off.

There is a command line option to turn the warnings on/off (--Wwarn=extension vs --Wdisable=extension) Should the default be warnings on or off?

@fruffy

fruffy commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

There is a command line option to turn the warnings on/off (--Wwarn=extension vs --Wdisable=extension) Should the default be warnings on or off?

Hmm, for practical reasons this seems like a pedantic mode.

I was mostly thinking to have a way to toggle extensions on/off in general. This way we could also prototype more work not compliant with the spec.

@ChrisDodd

ChrisDodd commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

There is a command line option to turn the warnings on/off (--Wwarn=extension vs --Wdisable=extension)

I was mostly thinking to have a way to toggle extensions on/off in general. This way we could also prototype more work not compliant with the spec.

--Werror=extension makes any use of an extension an error, effectively turning them off

@ChrisDodd ChrisDodd force-pushed the cdodd-decls branch 2 times, most recently from 9853a34 to c6750bb Compare April 28, 2026 05:24
@ChrisDodd ChrisDodd force-pushed the cdodd-decls branch 2 times, most recently from 7059b1e to 658f0a5 Compare May 10, 2026 23:36
Signed-off-by: Chris Dodd <cdodd@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Topics concerning the core segments of the compiler (frontend, midend, parser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants