Skip to content

HL/C compilation fails with Visual Studio when Haxe field is named restrict, _restrict, or __restrict #11378

Description

@joshtynjala

The C code for HashLink, when generated from the following Haxe code, cannot be compiled with Visual Studio's C compiler, cl.exe. It works with MinGW's gcc (and gcc on macOS and Linux), though.

class HlcRestrict {
	static function main() {
		new HlcRestrict();
	}

	public function new() {
	}

	public var restrict:String;
}

Compiled with the following options:

--main HlcRestrict
--hl generated/HlcRestrict.c

cl.exe command in Visual Studio developer shell:

 cl.exe /Ox /Fe:HlcRestrict.exe -I "<hashlink>\include" -I "generated" "generated/HlcRestrict.c" "<hashlink>\libhl.lib"

It results in the following error:

generated_std/HlcRestrict.h(22): error C2208: '_String *restrict ': no members defined using this type

Same result if you change it to _restrict or __restrict (one or two underscores).

public var _restrict:String;
public var __restrict:String;

However, if you change it to ___restrict with three underscores, cl.exe can successfully compile the generated C code:

public var ___restrict:String;

It looks like src/generators/hl2c.ml already has some code to rewrite certain field names when they conflict with C keywords, including restrict actually, but I guess that this behavior is specific to Visual Studio's C compiler that appears to have been missed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions