
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Before we leave our discussion of C, let's look at the way C represents
different data types. When you write a routine that shares data with a C
program, you must know how the C compiler stores data in memory.
The data types available in C can be divided into three general
categories: integer types, floating-point types, and other types.
. Integer types, including char, int, short, and long, are stored with
their low-order bytes first in the familiar "back-words" 8086 format.
In 8086 C implementations, char is 1 byte in size, int and short are 2
bytes, and long is 4 bytes. The integer data types may be specified as
either signed or unsigned.
. In Microsoft C, representations of floating-point data types (float and
double) are based on the IEEE standard for floating-point data
representation used in the 8087 math coprocessor. With this
representation, a float value is 4 bytes long and a double is 8 bytes
long. Despite the difference in size, a simple relationship exists
between float and double: You can convert a float to a double by
appending 4 bytes of zeros.
. Other C data types include pointers and strings. Pointers are address
values; near pointers are 2 bytes long and far pointers are 4 bytes
long. Strings are defined as arrays of type char. However, all strings
in C are stored as ASCIIZ strings; that is, as a string of bytes
terminated with a single zero byte. In a C program, you must
accommodate the extra byte when you declare a string. For example, you
would reserve storage for 64 bytes of string data plus the terminating
null byte like this:
char s[65];
In C, the value of the name s would be the address of the string data
associated with it. A subroutine called with s as a parameter can
obtain the value of s (the address of the string data) directly from
the stack and access the string data by reference to this address.
Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson