ID Number: Q23753
3.00 4.00 5.00 5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a
MS-DOS | OS/2
Summary:
In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax, the offset
parameter to fseek() takes a value of type long, so fseek() failing is
not likely to be the result of fseek() limits. On the other hand, this
situation does occur when using variables of type int to calculate the
offset. Because an int is limited to a maximum value of 32,767 (32K),
values assigned to ints between 32K and 64K are treated as negative.
An int will be automatically typecast to a long when passed to fseek()
but when this occurs, it is sign-extended. Thus, an int value above
32K that is represented as negative will be sign-extended to a
negative long. This, in turn, specifies a negative offset into the
file, which fails to produce the expected results.
When using the fseek() routine, be sure to use a long for specifying
the offset into the file.