home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / mswindo / programm / win32 / 2584 < prev    next >
Encoding:
Text File  |  1992-12-23  |  2.2 KB  |  87 lines

  1. Newsgroups: comp.os.ms-windows.programmer.win32
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
  3. From: jagrant@emr1.emr.ca (John Grant)
  4. Subject: Re: Bizzare array size link errors??
  5. Message-ID: <1992Dec23.233102.18242@emr1.emr.ca>
  6. Organization: Energy, Mines, and Resources, Ottawa
  7. References: <1992Dec22.211411.1147@mala.bc.ca>
  8. Date: Wed, 23 Dec 1992 23:31:02 GMT
  9. Lines: 76
  10.  
  11. In article <1992Dec22.211411.1147@mala.bc.ca> bigras@mala.bc.ca writes:
  12. >Hi,
  13. >There seems to be a weird little bug involving large
  14. >fixed arrays using the SDK.
  15. >
  16. >This does not compile and link the buff array properly.
  17. >
  18. > #include <stdio.h>
  19. > int i;  
  20. > long count;
  21. > long buff[1024*1024*4];                         
  22. > main()
  23. > {
  24. > for (i=0; i<=1; i++)
  25. >  {
  26. >  for (count=0; count<=1024*1024*4; count++)
  27. >    buff[count]=count;
  28. >  printf ("Win32\n");
  29. >  }
  30. > return(0);     
  31. > }
  32. >
  33. >When made this produces the following error:
  34. >
  35. > Microsoft(R) Windows NT Linker Version 2.19        
  36. > (C) 1989-1992 Microsoft Corp. All rights reserved. 
  37. >                                                   
  38. > simple.obj() : warning 0516: _buff is undefined    
  39. >
  40. >
  41. >Yet the following code makes fine, the only difference is the size
  42. >of the buff array!  So why is this? 
  43. >
  44. > #include <stdio.h>
  45. > int i;  
  46. > long count;
  47. > long buff[1024*1024*2];                         
  48. > main()
  49. > {
  50. > for (i=0; i<=1; i++)
  51. >  {
  52. >  for (count=0; count<=1024*1024*2; count++)
  53. >    buff[count]=count;
  54. >  printf ("Win32\n");
  55. >  }
  56. > return(0);     
  57. > }
  58. >
  59. >Various other sizes of char or int arrays exhibit similar
  60. >bizzare errors depending on the size of the array.
  61. >
  62. >Any ideas?
  63. >Tony Bigras
  64. >   BIGRAS@MALA.BC.CA 
  65. >
  66. >ok 
  67.  
  68.     Try this:
  69.         printf("%d",1024*1024*4);
  70.     
  71.     now try this:
  72.         printf("%ld",1024L*1024L*4L);
  73.  
  74.     Is there any difference?  Why?
  75.  
  76.     I'm not trying to be deliberately obtuse here, but don't
  77.     forget to declare your constants long or use a (long) cast.
  78.     If you don't they are assumed to be short (if less than 16 bits).
  79.     Calculations using short ints where the result is a long will
  80.     invariably be wrong.
  81. -- 
  82. John A. Grant                        jagrant@emr1.emr.ca
  83. Airborne Geophysics
  84. Geological Survey of Canada, Ottawa
  85.