home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctchnqs / 1991 / number3 / testhp.c < prev   
Text File  |  1991-05-22  |  1KB  |  41 lines

  1. /* TESTHP.C
  2.    test huge pointers for "normalization"
  3.    and correct comparison.
  4.  
  5.    by Terrence Vaughn  */
  6.  
  7. #include <stdio.h>
  8. void huge *normalize(void huge *);
  9.  
  10. main() {
  11.  
  12.  char far *cp;
  13.  char huge *hp, huge *hp1;
  14.  long l;
  15.  
  16.  cp = (char far *)0x2FFF00F2L; /* An easily visible addresss */
  17.  hp = (char huge *)cp;         /* Normalized * = 300E:0002   */
  18.  /* Did the cast have any effect? */
  19.  printf("far * =  %Fp\n",cp);
  20.  printf("huge * = %Fp\n",hp);
  21.  hp1 = hp;
  22.  hp1+=0;                      /* This works with TurboC */
  23.  printf("huge * +0 = %Fp\n",hp1);
  24.  hp1 = normalize(hp);         /* Force normalization  */
  25.  printf("Normalized * = %Fp\n",hp1);
  26.  if(hp == hp1) printf("Pointers equal.\n");
  27.  else printf("Pointers not equal.\n");
  28.  l = (long)(hp1 - hp);        /* Test pointer subtraction */
  29.  printf("%s subtraction= %li\n\n", (l) ? "Incorrect":"Correct", l);
  30. }
  31.  
  32. void huge *normalize(void huge *hp) {
  33.  
  34.  unsigned long base, para;
  35.  
  36.  base = (unsigned long) hp&0xFFFF000FL;
  37.  para = (unsigned long) hp&0x0000FFF0L;
  38.  para <<= 12;
  39.  return(void huge *)(base + para);
  40. }
  41.