Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!beach.cis.ufl.edu!thoth From: thoth@beach.cis.ufl.edu (Robert Forsman) Newsgroups: comp.lang.c Subject: Why are character arrays special (equal rights for structs) Message-ID: <19742@uflorida.cis.ufl.EDU> Date: 6 Feb 89 15:10:09 GMT Sender: news@uflorida.cis.ufl.EDU Reply-To: thoth@beach.cis.ufl.edu () Organization: UF CIS Department Lines: 48 I've got a question about what is in the standard concerning initializing pointers to objects other than chars. I have a program that works off of strings of ints (I ran out of char values and switched up). Anyway, I occasionally need to do stuff analogous to if (strcmp("hello",s)==0) but it would probably look like this if (intcmp((int*){43,21,5,0},command)==0) Now you don't really want to have to waste source code space to declare int strings, you want to declare them on the fly just like "hello". Unfortunately, I can't figure out how to do this so I have resorted to constructs like this : static int *GET_TORCH = { 34,52,0}; if (intcmp(GET_TORCH,command)==0) The problem is that even this gives errors in GCC. <> It IS one element, a pointer to several elements is one element!? When you say char *mesg="enter sum>"; the compiler doesn't complain. It figures out that enter sum is a character string that is supposed to reside in the data space and assigns mesg the pointer to it. I finally had to declare it this way : static int GET_TORCH[] = { 34,52,0}; This is probably the second best way of doing it, the stack isn't cluttered by pointers that have to be initialized and the value is static, but the best way would be the first (int *){ 34,52,0 }, no names to clutter the compiler and I wouldn't have wasted a line for a declaration. The question is, what does the standard say about structure and array constants (and arrays of structure constants, etc.)? I think that to not have the capability to declare something like that on the fly is crippled. If it isn't in the standard, somebody get it in there. If it IS in the standard, somebody get GNU to add it to their compiler (or tell me how it's done). ----------------------------------------------------------- If you're thinking of sueing my employer over my opinions then I have no other recourse than to tell you that you are lower than George Bush and Michael Dukkakis put together.