home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!micro-heart-of-gold.mit.edu!uw-beaver!cs.ubc.ca!mala.bc.ca!bigras
- From: bigras@mala.bc.ca
- Newsgroups: comp.os.ms-windows.programmer.win32
- Subject: Re: Bizzare array size link errors??
- Message-ID: <1992Dec27.195223.1158@mala.bc.ca>
- Date: 27 Dec 92 19:52:23 -0700
- References: <1992Dec22.211411.1147@mala.bc.ca> <1992Dec23.233102.18242@emr1.emr.ca>
- Organization: Malaspina College
- Lines: 95
-
- In article <1992Dec23.233102.18242@emr1.emr.ca>, jagrant@emr1.emr.ca (John Grant) writes:
- > 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?
- >
-
- Forcing the constants to long has no effect on the errors
- generated by the linker. This appears to be some weird bug
- related to the size of physical/virtual memory. It is triggered
- a various array sizes between 8MB and16MB on my 8MB system.
-
-
- > 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
-
- C has always stuck me as a poor general purpose language
- with its poor type enforcement. Surely I should not have to declare
- constants as long if they are being used on long variables. Is the
- compiler just a portable assembler, or is it supposed to do a bit of the
- work as well? I appreciate the ability to relax typing but are C compilers
- totally brain-dead?
-
- Tony Bigras BIGRAS@MALA.BC.CA
-
-
-