Syntax

S

Sheldon

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
 
K

Keith Thompson

Sheldon said:
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.
 
P

Pedro Graca

Sheldon said:
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.
 
S

Sheldon

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
 
P

Pedro Graca

Sheldon said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top