sven@cs.widener.edu (Sven Heinicke) (06/16/91)
Hi, I got this to work no problem: #include <stdio.h> #define TRY "look","at","this",NULL main() { char *first[] = {TRY}; int i; for(i = 0;first[i] != NULL;i++) printf("%s\n",first[i]); } That works fine. This does not work, is there any way to get something like this to compile? #include <stdio.h> #define TRY {"look","at","this",NULL},{"and","this","too",NULL} main() { char *first[][] = {TRY}; . . . } -- sven@cs.widener.edu Widener CS system manager Sven Mike Heinicke and Student (pssmheinicke@cyber.widener.edu (if you must))
dkeisen@leland.Stanford.EDU (Dave Eisen) (06/16/91)
In article <SVEN.91Jun15175330@laverne.cs.widener.edu> sven@cs.widener.edu (Sven Heinicke) writes: > >This does not work, is there any way to get something like this to compile? > >#define TRY {"look","at","this",NULL},{"and","this","too",NULL} >main() >{ > char *first[][] = {TRY}; No, not really. You can only leave the first array index blank when making an incomplete array declaration. Even though it seems that the compiler should be able to figure out that you want to declare first to be char *first[2][4], the language doesn't allow you to write char *first[][]. By the way, this has nothing to do with the preprocessor. You would have the exact same problem if it were written: char *first[][] = { {"look", "at", "this", NULL}, {"and", "this", "too", NULL} };
darcy@druid.uucp (D'Arcy J.M. Cain) (06/16/91)
In article <SVEN.91Jun15175330@laverne.cs.widener.edu> Sven Heinicke writes: >This does not work, is there any way to get something like this to compile? >#define TRY {"look","at","this",NULL},{"and","this","too",NULL} > char *first[][] = {TRY}; You need to tell it the size of the elements of 'first.' try: char *first[][4] = {TRY}; The error message from your compiler should have told you that. Here is what GNU C had to tell me: t.c: In function main: t.c:5: warning: array type has incomplete element type t.c:5: elements of array `first' have incomplete type t.c:5: array size missing in `first' t.c:5: storage size of `first' isn't known t.c:7: `first' undeclared (first use this function) t.c:7: (Each undeclared identifier is reported only once t.c:7: for each function it appears in.) t.c:5: warning: unused variable `first' make: *** [t] Error 1 Borland was a little less gabby but it told me that the size of array first was unknown. Even Microsoft had something to say, "first: no subscript' and cc on Unix said that line 5 had a null dimension. I am curious as to what compiler you are using and what sort of error message it gave you. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |
sven@cs.widener.edu (Sven Heinicke) (06/17/91)
In article <1991Jun16.135446.988@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
The error message from your compiler should have told you that. Here is
what GNU C had to tell me:
t.c: In function main:
t.c:5: warning: array type has incomplete element type
t.c:5: elements of array `first' have incomplete type
t.c:5: array size missing in `first'
t.c:5: storage size of `first' isn't known
t.c:7: `first' undeclared (first use this function)
t.c:7: (Each undeclared identifier is reported only once
t.c:7: for each function it appears in.)
t.c:5: warning: unused variable `first'
make: *** [t] Error 1
I am curious as to what compiler you are using and what sort of error
message it gave you.
Just to get things straight I was using GNU C too and, of course, got
about same errors.
From the replies I now know that it is ANSI C (bummen) and I have to
do somethng like *first[][5] = {TRY}; It was not exactely what I
wanted but I got it working.
--
sven@cs.widener.edu Widener CS system manager
Sven Mike Heinicke and Student
(pssmheinicke@cyber.widener.edu (if you must))
darcy@druid.uucp (D'Arcy J.M. Cain) (06/17/91)
In article <SVEN.91Jun16133706@laverne.cs.widener.edu> Sven Heinicke writes: >Just to get things straight I was using GNU C too and, of course, got >about same errors. Just recently Doug Gwyn announced that he is leaving comp.lang.c because of the SNR in this group. Hopefully he is just waiting in the wings, along with all the other gurus who have been silent lately, watching to see if we can get this group under control. Well here is my contribution. Before asking a question in this group make sure you have done the following: Run your problem code through lint(1) or use all the warnings your compiler will give you. With GNU C you can use -Wall to catch a lot of problems that are not necessarily syntax errors. Read the fucking manual. Read the Frequently Asked Question posting. Ask someone locally if possible. Having reached this stage if you still need to post then give as much information as possible without posting the whole program. Try to include the smallest possible program that exhibits the problem. Give the error messages or describe the output of the program. Above all try to give the impression that you have done your homework first. The best way to give that impression is to have done so. No one owes you an answer so try not to take the help offered for granted. This group should be your last resort, not your first. Oh, and don't forget the magic words your parents taught you. BTW, the above suggestions are doubly important for those who want to answer a question. -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |
nesbitt@herald.usask.ca (Murray Nesbitt) (06/18/91)
In article <1991Jun17.132947.5296@druid.uucp> D'Arcy J.M. Cain writes: >Just recently Doug Gwyn announced that he is leaving comp.lang.c because >of the SNR in this group. Hopefully he is just waiting in the wings, >along with all the other gurus who have been silent lately, watching to >see if we can get this group under control. Well here is my contribution. Don't count on it. This newsgroup is completely and probably irreparably out of control. What was once a Good Thing is now a Big Joke. >Before asking a question in this group make sure you have done the >following: > Run your problem code through lint(1) or use all the warnings > your compiler will give you. With GNU C you can use -Wall to > catch a lot of problems that are not necessarily syntax errors. > Read the fucking manual. > Read the Frequently Asked Question posting. > Ask someone locally if possible. This is excellent advice, but will hardly cut down on the type of noise that has recently forced the likes of Gwyn away from what was just weeks ago one of the most successfully self-moderated newsgroups. The recent absence of postings from Spencer, Heuer, Bernstein et al., is also noteworthy. Add to your list the suggestion that if the subject line contains any of the following phrases, there are likely more appropriate newsgroups for the posting: "Intel 386", "Windows", "VGA", "DOS", "PC", "keystroke", "PWB", "Extended keys", "SEATTLE YELLOW PAGES WANTED", "data compression", "for sale", "mac", "BGI", "Turbo C vs..." Posting to an appropriate newsgroup increases the probability of getting a quality response, and helps to ensure that when one encounters a problem with *the C programming language*, knowledgeable people will still be reading and contributing to comp.lang.c. Not to slam anyone in particular, but there has been so much crap posted in recent weeks from people with "fidonet" as part of their email address, that it makes one wonder how this fidonet organization can keep afloat in its own ineptitude. 1/2 :-) for the humour-impaired. >Oh, and don't forget the magic words your parents taught you. My grandfather used to say: "All the world isn't an IBM PC" and "Just because you're coding it in C, doesn't make it a C problem." >BTW, the above suggestions are doubly important for those who want to >answer a question. Oh God, are they ever. Are the remaining gurus paying attention? >-- >D'Arcy J.M. Cain (darcy@druid) | >D'Arcy Cain Consulting | There's no government >Toronto, Ontario, Canada | like no government! >+1 416 424 2871 | Murray -- /* Murray Nesbitt * And what is good, Phaedrus * * nesbitt@herald.usask.ca * And what is not good - * * nesbitt@sask.usask.ca * Need we ask anyone to tell us these things? */
henry@zoo.toronto.edu (Henry Spencer) (06/18/91)
In article <1991Jun18.092200.13541@herald.usask.ca> nesbitt@herald.usask.ca (Murray Nesbitt) writes: >The recent absence of postings from Spencer, Heuer, Bernstein et al., >is also noteworthy. Don't overlook the fact that the Usenix conference was last week, and a lot of us were there relaxing rather than here posting. -- "We're thinking about upgrading from | Henry Spencer @ U of Toronto Zoology SunOS 4.1.1 to SunOS 3.5." | henry@zoo.toronto.edu utzoo!henry
robert@isgtec.UUCP (Robert Osborne) (06/19/91)
In article <1991Jun17.132947.5296@druid.uucp>, darcy@druid.uucp (D'Arcy J.M. Cain) writes: |> |> Before asking a question in this group make sure you have done the |> following: |> |> [...] |> |> Read the fucking manual. |> |> Read the Frequently Asked Question posting. I would say that these two sources could answer most, if not all, of the stupid questions that are being posted here with increasing regularity. |> BTW, the above suggestions are doubly important for those who want to |> answer a question. I think the reason that Torek, Spencer, Gwyn, etc. are no longer participating in this group is not the stupid questions, it's the stupid answers (all 10-12 of them for each stupid question!). What's worse is these fucking morons feel obliged to argue with Gwyn etc. (I guess having everybody in comp.lang.c THINK they are an idiot isn't enough; they have to PROVE it). At least Blair is intelligent and obnoxious :-). Don't try to answer any question unless you KNOW the answer (if I see one more "I think that..." followed by a wrong explanation I'll scream). Rob. -- Robert A. Osborne ...uunet!utai!lsuc!isgtec!robert or robert@isgtec.uucp
wolfram@cip-s08.informatik.rwth-aachen.de (Wolfram Roesler) (06/19/91)
robert@isgtec.UUCP (Robert Osborne) writes: >|> Read the fucking manual. >|> Read the Frequently Asked Question posting. >I would say that these two sources could answer most, if not all, of the >stupid questions that are being posted here with increasing regularity. So close down c.l.c., post the FAQ somewhere and make a new group where the gurus answer intelligent questions and write RTFM to all the others. And please make a second group where all of the non-gurus can discuss their problems. However, if I have a question and post it, I expect somebody to answer, even if he's not a guru, and even if the answer is not 100% correct. And I like to respond to questions and incorrect answers. Remember: nobody is perfect. The gurus might know everything but the typical guru answer is too short for a novice to understand. >I think the reason that Torek, Spencer, Gwyn, etc. are no longer >participating in this group is not the stupid questions, it's the >stupid answers (all 10-12 of them for each stupid question!). What's So give 'em their guru group where they are among themselves and can discuss on their level. >worse is these fucking morons feel obliged to argue with Gwyn etc. >(I guess having everybody in comp.lang.c THINK they are an idiot isn't > enough; they have to PROVE it). How fine that you obviously belong to the intelligent, smart and sane people here. >Don't try to answer any question unless you KNOW the answer (if I see one >more "I think that..." followed by a wrong explanation I'll scream). So scream. I won't be listening. I dont like arrogant fucking morons telling me what to do. How about _friendly telling_ people that they are wrong? Have you never been a beginner? Even if you wrote your first compiler at the age of 4, there's no reason to insult people who are not as phantastic as you are. \/\/olfram
bhoughto@hopi.intel.com (Blair P. Houghton) (06/21/91)
In article <1991Jun18.092200.13541@herald.usask.ca> nesbitt@herald.usask.ca (Murray Nesbitt) writes: >Don't count on it. This newsgroup is completely and probably >irreparably out of control. What was once a Good Thing is now a Big >Joke. Y'know, the funny thing is that I haven't noticed a sparrow's tit of difference in the level of content or S/N ratio from the vox populi in this group. There's just many more populi voxing, just as there are many more machines spreading the news (in fact, I dare say the net itself has grown about twice as fast as this group). I think Doug et al simply matured (as I have) beyond their earlier state of awareness and simply didn't notice (as I, on the other hand, have) that the fat part of the bell-curve is getting farther below them because they're reaching into the thin part above (e.g., I think it's conceivable that Doug, Karl, Henry, and Chris could be shown to know more now about C than Dennis Ritchie and Brian Kernighan knew about it in 1978, when they probably first learned it, modulo enhancements due to standardization, but they'd never be able to admit it to themselves; I could admit it--because I've got an ego the size of the average Carolinian island golf resort, a fact I've never hidden nor denied--though I haven't, because I think I'm still shy a nuance or two, but I'm a damn sight heftier a hacker than the day I entered this evanescent realm). >My grandfather used to say: "All the world isn't an IBM PC" and "Just >because you're coding it in C, doesn't make it a C problem." Classical customer engineering paradox: if the customer is lost, he can't tell you how to find him, even if he recognizes he's not where he's supposed to be. >Oh God, are they ever. Are the remaining gurus paying attention? Shhhh. Wait until they're all croaking pretty good, then if you shine your flashlight out across the water of the pond, you can see their eyes shining back at you... --Blair "If I get to be a guru, do I have to get the Beatles hooked on pot and sitars?"
eoo@let.rug.nl (Eize Oosting) (06/21/91)
In article <SVEN.91Jun15175330@laverne.cs.widener.edu> sven@cs.widener.edu (Sven Heinicke) writes: > >Hi, I got this to work no problem: > >#include <stdio.h> >#define TRY "look","at","this",NULL >main() >{ > char *first[] = {TRY}; > int i; > for(i = 0;first[i] != NULL;i++) > printf("%s\n",first[i]); >} > >That works fine. >This does not work, is there any way to get something like this to compile? > >#include <stdio.h> >#define TRY {"look","at","this",NULL},{"and","this","too",NULL} >main() >{ > char *first[][] = {TRY}; >. . . >} > You are very lucky that your compiler compiled you first program, because it is not usual to be able to auto-initialise arrays. I think your compiler has a way around with the first program, however the second program would use a more complex initialisationroutine. I think that's way it fails to compile. It is, however, no problem if you make the declarations global or static. But then they are initialised only once, not each time the function is entered. /\__________/\ /\___________________________________________________/\ / \ / \ | Letteren- | Marvin Minsky once defined Artificial Intelligence as: | | Faculteit | '... the science of making machines do things that | | R.U. Groningen | would require intelligence if done by men'. | | The Netherlands| | | | Does this include formatting a floppy? | | eoo@let.rug.nl | Eize Oosting | \ __________ / \ ___________________________________________________ / \/ \/ \/ \/