Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: C question -- pointer to array of characters Message-ID: <11332@smoke.BRL.MIL> Date: 19 Oct 89 09:29:40 GMT References: <6569@ficc.uu.net> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <6569@ficc.uu.net> kunkee@ficc.uu.net (randy kunkee XNX MGR) writes: > char (*foo)[]; > char bar[20]; > foo = bar; >Does not work (well, it works, but the compiler complains). >Is my C compiler broken? No. There are (at least) three problems in this code: (1) bar is the same in the assignment expression as &bar[0], i.e. a char*, which is not compatible with foo. (2) foo has an incomplete type -- it would be impossible for the compiler to generate code to perform pointer arithmetic involving foo, because the size of the object to which foo points has not been specified. >To put it another way, is there a declaration of "bar" that will >make the above assignment compile silently, and which allocates >storage for characters? (3) there are five ways to allocate storage in C: (a) string literals (b) static variables (c) auto variables (d) function arguments (e) invocation of malloc()/realloc()/calloc() execution of an assignment expression is not a way to allocate storage.