Data types

A User Language Program can define variables of different types, representing the different kinds of information available in the EAGLE data structures. The four basic data types are

Besides these basic data types there are also high level Object Types, which represent the data structures stored in the EAGLE data files.

The special data type void is used only as a return type of a function, indicating that this function does not return any value.

Data type Usage Size
char The data type char is used to store single characters, like the letters of the alphabet, or small unsigned numbers. A variable of type char has a size of 8 bit (one byte), and can store any value in the range 0..255.
int The data type int is used to store signed integral values, like the coordinates of an object. A variable of type int has a size of 32 bit (four bytes), and can store any value in the range -2147483648 to 2147483647.
real The data type real is used to store signed floating point values, like the grid distance. A variable of type real has a size of 64 bit (eight byte), and can store any value in the range ±2.2e-308 to ±1.7e+308 with a precision of 15 digits.
string The data type string is used to store textual information, like the name of a part or net. A variable of type string is not limited in it's size (provided there is enough memory available).

Accessing string indices

Variables of type string are defined without an explicit size. They grow automatically as necessary during program execution.

The elements of a string variable are of type int and can be accessed individually by using [index]. The first character of a string has the index 0:

string s = "Layout";
printf("Third char is: %c\n", s[2]);

This would print the character 'y'. Note that s[2] returns the third character of s! A lossless conversion to char is possible for standard ASCII strings:

string s = "Layout";
char c = s[2];

Implementation details

The data type string is actually implemented like native C-type zero terminated strings. Looking at the following variable definition

string s = "abcde";

s[4] is the character 'e', and s[5] is the character '\0', or the integer value 0x00. This fact may be used to determine the end of a string without using the strlen() function, as in

for (int i = 0; s[i]; ++i) {
    // do something with s[i]
    }

It is also perfectly ok to "cut off" part of a string by "punching" a zero character into it:

string s = "abcde";
s[3] = 0;

This will result in s having the value "abc". Note that everything following the zero character will actually be gone, and it won't come back by restoring the original character. The same applies to any other operation that sets a character to 0, for instance --s[3].

Type Conversions

The result type of an arithmetic expression, such as a + b, where a and b are different arithmetic types, is equal to the "larger" of the two operand types. Arithmetic types are char, int and real (in that order). So if, e.g. a is of type int and b is of type real, the result of the expression a + b would be real.

Typecast

The result type of an arithmetic expression can be explicitly converted to a different arithmetic type by applying a typecast to it. The general syntax of a typecast is type(expression) where type is one of char, int or real, and expression is any arithmetic expression.

When typecasting a real expression to int, the fractional part of the value is truncated!