home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
- Subject: Re: extern: interesting case...
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1993Jan6.200359@rbg.informatik.th-darmstadt.de>
- Date: Wed, 6 Jan 1993 19:03:59 GMT
- References: <bibhas.726341439@femto.engr.mun.ca>
- Nntp-Posting-Host: rbhp58.rbg.informatik.th-darmstadt.de
- Organization: TH Darmstadt
- Keywords: extern
- Lines: 29
-
- In article <bibhas.726341439@femto.engr.mun.ca>, bibhas@pico.engr.mun.ca (Bibhas Bhattacharya) writes:
- > When I declare:
- > extern char line[];
- > for the variable "line" which was defined in another file as:
- > char line[80];
- > everything works fine. But when I do:
- > extern char *line;
- > the program dumps core. I can't figure out the difference, especially when
- > extern declaration is not supposed to reserve any memory or anything. When
- > I looked up K&R, the correct declaration would be: extern char line[];.
-
- A pointer isn't the same as an array. (Try compiling extern char *line;
- extern char line[80]; => conflicting types for `line')
- Given extern char line[], the compiler knows, that line is an constant adress,
- where chars are stored. Given extern char *line, the compiler looks at line
- as a variable (=constant adress) where a pointer is stored, which points to
- chars.
-
- In assembler this would look like this:
-
- line: dc.b "text",0 ; char line[]="text";
- +--------------------------------------------
- text: dc.b "text",0
- line: dc.l text ; char *line="text";
-
- --
- Walter Misar | It is impossible to enjoy
- misar@rbg.informatik.th-darmstadt.de | idling thoroughly unless
- | one has plenty of work to do.
-