Types, operators, and expressions, Variable names and data types/sizes, Types, operators, and expressions -18 – Rockwell Automation 2098-IPD-xxx Ultra5000 C Programming using the Motion Library User Manual

Page 30: Variable names and data types/sizes -18

Advertising
background image

Publication 2098-PM001E-EN-P — July 2002

1-18

Programming Motion Control in C

Types, Operators, and
Expressions

The C language allows you a great deal of flexibility in deciding what
type of data the Ultra5000 will use. Some of the data is preset or static,
such as (#define ACCEL 1000), while other data changes or is assigned
different values as your program runs (long partcount; is an example).
The preset and unchanging data is called a constant, while the
changing data is called a variable. Expressions combine variables and
constants to produce new values.

Variable Names and Data Types/Sizes

You are already familiar with declaring one variable. The code

long target

declares the variable target as a long integer. This one line of code
covers the rules for C variables:

• Each variable must have a unique name.
• Variables must begin with a letter.
• Before you can use a variable, you must declare or define it by its

type. The following table lists the eight keywords for defining a
variable.

Keyword:

Description:

Example:

int

Integer: A positive or negative value of up to
32-bits in length.

int main ()

long

Long word: An integer of the maximum length,
32- bits with a range of ±2,147,483,647.

long int ()

short

Short word: An integer smaller than the largest
integer; 32- bits in length.

short int ()

unsigned

A non-negative number (i.e., a number greater
than or equal to 0).

unsigned int ()
or
unsigned int ()

char

Typographic symbols, such as A, & and + or small
integers, up to 32-bits in length.

float

A fractional value or a value with a decimal
point. 32-bits in length, but typically with a range
from 10

–38

to 10

38

.

salary ()

double

A longer fractional or decimal value. It allows for
additional significant places and/or larger
exponents than a basic float. 32-bits in length,
but typically with a 10-digit base and an
exponent from –307 to 308.
Note: A long double typically provides an 18-digit
base and an exponent from –4931 to 4932.

double salary ()

signed

A number with a positive or a negative value.

Advertising