home *** CD-ROM | disk | FTP | other *** search
- Q32244 Huge Arithmetic Not Being Applied to Huge Pointer
- C Compiler
- 5.10 | 5.10
- OS/2 | MS-DOS
-
- Summary:
- In small model, huge-pointer arithmetic is not being applied to a
- binary expression involving a huge pointer and an integer.
- Given a pointer declared as follows:
-
- char huge * ptr;
-
- the following statements should be equivalent:
-
- ptr = ptr + 128000; /* this fails */
- ptr = (char huge *) ptr + 128000; /* this works only if */
- /* compiled with -Od */
- ptr = ptr + foo(); /* this works */
- /* foo() returns 128000 */
-
- The first statement incorrectly adds together only the offsets,
- whereas the second and third statements add both segments and offsets,
- as specified by the huge keyword.
- The workarounds to this problem are demonstrated in the example:
- either use an explicit typecast and disable optimization with the
- compiler option /Od (or -Od), or make a function call to return the
- value.
- This problem should be corrected in the next release of C.
-
- More Information:
- The following program demonstrates the problem:
-
- #include <stdio.h>
-
- void main(void);
- long foo(void);
-
- char huge * ptr;
-
- void main(void)
- {
- printf("ptr is 0.\n");
- ptr = 0;
- ptr = ptr + 128000;
- printf("ptr + 128000 = %lp...Wrong!\n", ptr);
-
- ptr = 0;
- ptr = (char huge *) ptr + 128000;
- printf("(char huge *) ptr +128000 = %lp...Correct.\n", ptr);
-
- ptr = 0;
- ptr = ptr + foo();
- printf("ptr + foo() = %lp...Also correct.\n", ptr);
- }
-
- long foo(void)
- {
- return 128000;
- }
-
-
- Keywords: buglist5.10
- Updated 88/08/25 05:19
-