Announcement

Collapse
No announcement yet.

Translating C to PB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Translating C to PB

    What would be the best alternative for the following C/C++ statement:
    Code:
    const double f = ...
    Thanks.

    ------------------

  • #2
    MACRO f = ...

    ------------------
    Website: http://com.it-berater.org
    SED Editor, TypeLib Browser, COM Wrappers.
    Forum: http://www.forum.it-berater.org
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Thanks, it did work. Until it got more complex.

      I'm now starting to get nesting errors for all the macro's. The code I am translating from C++ to PB is a very complex formule.

      Are there any other alternatives to 'const double'?

      I did try' %f = ... ' Which does work for some, but not for things like '%f = sqr(...)'

      Thanks.

      ------------------

      Comment


      • #4
        If in C, const is used, I wonder how one can still use
        f = sqrt(....);

        with it.

        So, for const, there is only one possibility %F in PB.

        Maybe you should give us the whole picture ?


        ------------------
        I'd rather be hated for who I am, then being loved for who I am not.
        So here we are, this is the end.
        But all that dies, is born again.
        - From The Ashes (In This Moment)

        Comment


        • #5
          To be more specific, it's not C but C++ (does that matter??).

          Here is an example from the, way to big to post here, code:
          Code:
              const double ee=f*(2-f);  
              const double e=sqrt(ee);  
              const double eea = ee/(1.0-ee);
          ------------------

          Comment


          • #6
            This works (macros can be nested):
            Code:
            MACRO f=1.5
            MACRO ee=f*(2-f) 
            MACRO e=SQR(ee)  
            MACRO eea = ee/(1.0-ee)  
            
            FUNCTION PBMAIN
              MSGBOX STR$(e)+STR$(eea)
            END FUNCTION
            %name is OK for integer constants. For floating point you need to use a macro. But why not simply declare a variable whose value you set only once at the start of the code? Is there a reason it has to be a constant?

            Comment


            • #7
              See "Floating Point Data Types" in the PB Help File for floating point

              (Unless of course if someone tells me I can not use the following in PB to replace C)

              Code:
              Dim ee AS DOUBLE
              DIM f AS DOUBLE
              DIM e AS DOUBLE
              DIM eeaa AS DOUBLE
              ee=f*(2-f)  
              e=sqrt(ee)  
              eea = ee/(1.0-ee)
              OR
              Code:
              #ee=#f*(2-#f)  
              #e=sqrt(#ee)
              #eea = #ee/(1.0-#ee)
              sort of thing.


              ------------------
              Engineer's Motto: If it aint broke take it apart and fix it

              "If at 1st you don't succeed... call it version 1.0"

              "Half of Programming is coding"....."The other 90% is DEBUGGING"

              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

              Comment


              • #8
                Julian --

                There are a variety of ways to deal with this type of issue, but the simplest is likely to be use of a MACRO as described before. As complexity of expressions grow, you just need to be aware that precedence of operators could come into play. Therefore, if you simply enclose the terms in parentheses, it should force evaluation in the sequence originally expected.

                MACRO ee = (f*(2-f))
                MACRO e = (sqrt(ee))
                MACRO eea = (ee/(1.0-ee))

                Best regards,

                Bob Zale
                PowerBASIC Inc.


                ------------------

                Comment

                Working...
                X