Syntax

Discussion in 'C Programming' started by Sheldon, Mar 22, 2006.

  1. Sheldon

    Sheldon Guest

    Hi,

    I am not a programmer in C and I am just trying to copy part of a
    C-program into another language. I was wondering if someone could tell
    me what this means:

    ssp_lon=(Float_64)aux;

    Does it mean that the variable ss_p = aux; and is converted to a
    Float64?

    I think that is what it means but I am not sure.

    Thanks,
    /Sheldon
     
    Sheldon, Mar 22, 2006
    #1
    1. Advertising

  2. Sheldon

    lostpencil Guest

    u r right.
    By the way, "ssp_lon" is not "ss_p"
     
    lostpencil, Mar 22, 2006
    #2
    1. Advertising

  3. "Sheldon" <> writes:
    > I am not a programmer in C and I am just trying to copy part of a
    > C-program into another language. I was wondering if someone could tell
    > me what this means:
    >
    > ssp_lon=(Float_64)aux;
    >
    > Does it mean that the variable ss_p = aux; and is converted to a
    > Float64?
    >
    > I think that is what it means but I am not sure.


    Presumably Float_64 is a typedef, probably for some floating-point
    type. Keep in mind that Float_64 and Float64 are two distinct
    identifiers; likewise for Float_64 vs. float_64, and ssp_lon vs. ss_p.

    A type name in parentheses is, at least in this case, a cast operator,
    which specifies an explicit type conversion. The value of aux is
    converted to Float_64, and the result is assigned to the variable
    ssp_lon.

    Since you're not a C programmer you may or may not be interested in
    what follows.

    Cast operators should almost always be viewed with suspicion.
    Conversions between numeric types (integer or floating-point) are done
    implicitly. The statement above could almost certainly be written as:

    ssp_lon = aux;

    If ssp_lon is of type Float_64, the cast is unnecessary. If it's not,
    the cast is likely to be wrong.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Mar 23, 2006
    #3
  4. Sheldon

    Pedro Graca Guest

    Sheldon wrote:
    > I was wondering if someone could tell me what this means:
    >
    > ssp_lon=(Float_64)aux;
    >
    > Does it mean that the variable ss_p = aux; and is converted to a
    > Float64?
    >
    > I think that is what it means but I am not sure.


    First a conversion to Float_64 is attempted for `aux`.
    If Float_64 is "smaller" than the original type of aux the
    conversion result may be a different value; if `aux` is an
    out-of-range value for Float_64 the result is undefined.

    Then the resulting Float_64 value is converted to the type of `ssp_lon`
    (if needed and with the same caveats as before) and assigned to
    that variable.


    So, unless you need two conversions instead of one (when `ssp_lon` is
    not of type Float_64), that should have been written as

    ssp_lon = aux;

    which works as expected for compatible types.

    --
    If you're posting through Google read <http://cfaj.freeshell.org/google>
     
    Pedro Graca, Mar 23, 2006
    #4
  5. Sheldon

    Sheldon Guest

    Thank you!

    It is good to have experts on hand.

    Much obliged. Sorry about the typo ssp_lon / ss_p. Late night at the
    key board, you know :)

    Sheldon
     
    Sheldon, Mar 23, 2006
    #5
  6. Sheldon

    Pedro Graca Guest

    Sheldon wrote:
    > It is good to have experts on hand.


    I agree. I'm not one (far from it) but I try to answer with valid
    information knowing that anything wrong I write will rapidly be
    corrected by the experts here.

    --
    If you're posting through Google read <http://cfaj.freeshell.org/google>
     
    Pedro Graca, Mar 23, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gabriele renzi
    Replies:
    2
    Views:
    233
    gabriele renzi
    Dec 31, 2005
  2. Ken Bloom
    Replies:
    3
    Views:
    231
  3. Good Night Moon
    Replies:
    9
    Views:
    307
    Rick DeNatale
    Jul 25, 2007
  4. Jacob Grover
    Replies:
    5
    Views:
    340
    Jacob Grover
    Jul 18, 2008
  5. Mark Richards
    Replies:
    3
    Views:
    337
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page