Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4239819

static final long constants generated in .h files don't compile on Windows.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.2.0
    • tools
    • None
    • beta
    • sparc
    • solaris_2.5.1

      From: Peter Korn <###@###.###>
      Subject: Sharing constants between Java and Windows
      To: ###@###.###

      Hi,

      I want to define some constants (static finals) in Java that then, through
      the magic of JNI, I can reference from my Windows native methods.

      Fer instance, I have the file "blah.java":

        package foo.bar;

        class blah {
          static final long bleh = 1;
          public blah() {}
          public native void huh();
        }

      which then results in the header file (through the magic of JNI)
      foo_bar_blah.h:

        ...
        #ifdef __cplusplus
        extern "C" {
        #endif
        #undef foo_bar_blah_bleh
        #define foo_far_blah_bleh 1LL
        ...

      So then I create my code blah.cpp, which wants to compare a jlong variable
      to the constant:

        ...
        if (myJLongVar == (jlong) foo_far_blah_bleh) {
        ...

      But I get a series of compile errors from MSDev 5.0:
        "error C2059: bad suffix on number"
        "error C2146: missing ')' before identifier 'L'"
        "error C2059: syntax error : ')'"
        "error C2065: 'L' : undeclared identifier"
        "error C2143: syntax error : missing ';' before '{'"

      any ideas as to what I'm doing wrong? Is javah generating header files that
      MSDev 5.0 can't parse? Are there compiler options I should be using to get
      it to handle "#define foo_far_blah_bleh 1LL"?

      Thanks,

      Peter

            gafter Neal Gafter (Inactive)
            apalanissunw Anand Palaniswamy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: