Skip to content

Incompatible with MSVC: initializer is not a constant #1275

Closed

Description

@kdada

The INFINITY macro and 1.0 / 0.0 are not constants in MSVC and need to be corrected for global.Infinity, number.NEGATIVE_INFINITY, and number.POSITIVE_INFINITY.

As shown below:

static const JSCFunctionListEntry js_number_funcs[] = {
-    JS_PROP_DOUBLE_DEF("NEGATIVE_INFINITY", -INFINITY, 0 ),
-    JS_PROP_DOUBLE_DEF("POSITIVE_INFINITY", INFINITY, 0 ),
+    JS_PROP_U2D_DEF("NEGATIVE_INFINITY", 0xFFF0ull<<48, 0 ), // workaround for msvc
+    JS_PROP_U2D_DEF("POSITIVE_INFINITY", 0x7FF0ull<<48, 0 ), // workaround for msvc
};

static const JSCFunctionListEntry js_global_funcs[] = {
-    JS_PROP_DOUBLE_DEF("Infinity", 1.0 / 0.0, 0 ),
+    JS_PROP_U2D_DEF("Infinity", 0x7FF0ull<<48, 0 ), // workaround for msvc
};

Activity

  1. saghul commented on Dec 20, 2025

    @saghul
    Contributor

    Our CI compiles with MSVC just fine. What version are you trying to use?

  2. kdada commented on Dec 20, 2025

    @kdada
    Author

    Visual Studio 2022
    Exe Path: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64
    cl.exe Version: Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34438 for x64
    Windows Kits: 10.0.22621.0

  3. kdada commented on Dec 20, 2025

    @kdada
    Author

    for the 3 macros, it will generate:

    #define JS_PROP_DOUBLE_DEF(name,val,prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, { .f64 = val } }
    Expands to:
    
    { "NEGATIVE_INFINITY", 0, 6, 0, { .f64 = -((float)(1e+300 * 1e+300)) } }
    
    #define JS_PROP_DOUBLE_DEF(name,val,prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, { .f64 = val } }
    Expands to:
    
    { "POSITIVE_INFINITY", 0, 6, 0, { .f64 = ((float)(1e+300 * 1e+300)) } }
    
    #define JS_PROP_DOUBLE_DEF(name,val,prop_flags) { name, prop_flags, JS_DEF_PROP_DOUBLE, 0, { .f64 = val } }
    Expands to:
    
    { "Infinity", 0, 6, 0, { .f64 = 1.0 / 0.0 } }
    
  4. bnoordhuis commented on Dec 20, 2025

    @bnoordhuis
    Contributor

    We've had that issue before with NAN, see f93dd58. I'll open a pull request.

  5. kdada commented on Mar 26, 2026

    @kdada
    Author

    #1276 only fixed the definition in js_number_funcs, but not js_global_funcs, causing MSVC to still report compilation errors.

    cc @bnoordhuis

  6. added a commit that references this issue on Mar 26, 2026
  7. saghul commented on Mar 26, 2026

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

Metadata

Metadata

Assignees

No one assigned

    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