home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.win32
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
- From: jagrant@emr1.emr.ca (John Grant)
- Subject: Re: Bizzare array size link errors??
- Message-ID: <1992Dec23.233102.18242@emr1.emr.ca>
- Organization: Energy, Mines, and Resources, Ottawa
- References: <1992Dec22.211411.1147@mala.bc.ca>
- Date: Wed, 23 Dec 1992 23:31:02 GMT
- Lines: 76
-
- In article <1992Dec22.211411.1147@mala.bc.ca> bigras@mala.bc.ca writes:
- >Hi,
- >There seems to be a weird little bug involving large
- >fixed arrays using the SDK.
- >
- >This does not compile and link the buff array properly.
- >
- > #include <stdio.h>
- > int i;
- > long count;
- > long buff[1024*1024*4];
- > main()
- > {
- > for (i=0; i<=1; i++)
- > {
- > for (count=0; count<=1024*1024*4; count++)
- > buff[count]=count;
- > printf ("Win32\n");
- > }
- > return(0);
- > }
- >
- >When made this produces the following error:
- >
- > Microsoft(R) Windows NT Linker Version 2.19
- > (C) 1989-1992 Microsoft Corp. All rights reserved.
- >
- > simple.obj() : warning 0516: _buff is undefined
- >
- >
- >Yet the following code makes fine, the only difference is the size
- >of the buff array! So why is this?
- >
- > #include <stdio.h>
- > int i;
- > long count;
- > long buff[1024*1024*2];
- > main()
- > {
- > for (i=0; i<=1; i++)
- > {
- > for (count=0; count<=1024*1024*2; count++)
- > buff[count]=count;
- > printf ("Win32\n");
- > }
- > return(0);
- > }
- >
- >Various other sizes of char or int arrays exhibit similar
- >bizzare errors depending on the size of the array.
- >
- >Any ideas?
- >
- >Tony Bigras
- >
- > BIGRAS@MALA.BC.CA
- >
- >ok
-
- Try this:
- printf("%d",1024*1024*4);
-
- now try this:
- printf("%ld",1024L*1024L*4L);
-
- Is there any difference? Why?
-
- I'm not trying to be deliberately obtuse here, but don't
- forget to declare your constants long or use a (long) cast.
- If you don't they are assumed to be short (if less than 16 bits).
- Calculations using short ints where the result is a long will
- invariably be wrong.
- --
- John A. Grant jagrant@emr1.emr.ca
- Airborne Geophysics
- Geological Survey of Canada, Ottawa
-