C++ convert to Java?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wizious
    New Member
    • Mar 2008
    • 3

    C++ convert to Java?

    Hello, I am currently converting a C++ program into Java, but I cannot find the equivilant to UCHAR_MAX in Java. Does anyone know this?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Look at the static constants in the Character class. I think the one you
    want is MAX_VALUE.

    kind regards,

    Jos

    Comment

    • wizious
      New Member
      • Mar 2008
      • 3

      #3
      I have a statement,

      ColorJitter::Co lorJitter() // Class constructor
      {
      int i; // Loop index
      status = TRUE;
      // Initialize jitter lookup table pointers
      pirand = NULL;
      pxrand = NULL;
      pyrand = NULL;
      noise = 1; // Set default noise level

      if ((pirand = new int[C_TableSize]) == NULL)
      {
      status = FALSE;
      return;
      }


      "status" as already been defined as a boolean in a previous class which this extends. I want to convert the if statement to Java but I am having trouble doing this.the reference "C_TableSiz e" has been declared in a previous class which this extends as well, it has declared:

      public static final int C_TableSize = 1024;


      Does anyone have any suggestions?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by wizious
        Does anyone have any suggestions?
        What suggestion? A public static final int variable should be visible in a subclass.
        What exactly is the problem then? Don't say "it doesn't work" please. Give us
        compilation and/or runtime error messages.

        kind regards,

        Jos

        Comment

        • wizious
          New Member
          • Mar 2008
          • 3

          #5
          well if I enter " if ((pirand = new int[C_TableSize]) == NULL) "

          straight into Java, I get a " ')' expected" error at the line where the if statement is declared.

          At first I tried rewriting it as a " if ((pirand = int[] C_TableSize == null)" statement instead, I get a ".class expected" error instead.

          I think the most likely error is that I dont know what they are trying to do in the initial c++ code, so therefore its much harder for me to find a way to implement it in Java.

          Regards,

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by wizious
            well if I enter " if ((pirand = new int[C_TableSize]) == NULL) "

            straight into Java, I get a " ')' expected" error at the line where the if statement is declared.

            At first I tried rewriting it as a " if ((pirand = int[] C_TableSize == null)" statement instead, I get a ".class expected" error instead.

            I think the most likely error is that I dont know what they are trying to do in the initial c++ code, so therefore its much harder for me to find a way to implement it in Java.

            Regards,
            Try to change that NULL to lowercase null in that first version. Java doesn't know
            anything about defined values but it does know what null (lowercase) is.

            kind regards,

            Jos

            ps. it's rather hopeless to try to translate something from language A to language B
            when you don't know what language A does ...

            Comment

            • Laharl
              Recognized Expert Contributor
              • Sep 2007
              • 849

              #7
              That won't work no matter how you tweak it, since Java doesn't support inline assignments. Just assign it before the if, then check if it's null.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by Laharl
                That won't work no matter how you tweak it, since Java doesn't support inline assignments. Just assign it before the if, then check if it's null.
                *ahem*, slight correction: in Java an assignment token is an operator and an
                assignment is an expression so you can do things like this:

                [code=java]
                if ((foo= new int[42]) != null)
                [/code]

                Of course some people don't find it readable; but it is still perfectly valid.

                kind regards,

                Jos

                Comment

                • Laharl
                  Recognized Expert Contributor
                  • Sep 2007
                  • 849

                  #9
                  Huh, you learn something new every day. I'd figured they'd disallowed that to avoid the fun in C that you get with that when you forget that second =.

                  Comment

                  Working...