Article View: comp.lang.misc
Article #22Re: Robots...
From: Larry D. Pyeatt
Date: Fri, 30 Oct 1992 17:42
Date: Fri, 30 Oct 1992 17:42
72 lines
2969 bytes
2969 bytes
In article <mwm.2gwf@contessa.palo-alto.ca.us>, mwm@contessa.palo-alto.ca.us (Mike Meyer) writes:
|> In <1992Oct29.163702.9849@texhrc.uucp>, pyeatt@Texaco.com (Larry D. Pyeatt) wrote:
|> > In article <SPACKMAN.92Oct28142448@disco-sol.dfki.uni-sb.de>, spackman@disco-sol.dfki.uni-sb.de (Stephen Spackman) writes:
|> > |> both have really
|> > |> stupid type declaration syntax.
|> >
|> > What could be simpler and more clear than:
|> >
|> [Pascal deleted - or is that wishfull thinking :-]
|> > or in C:
|> >
|> > typedef float[26] mytype;
|> > typedef char[201] yourtype;
|>
|> Well, to start with, those are wrong. That should be:
|>
|> typedef float mytype[26] ;
|> typedef char yourtype[201] ;
|>
|> Which just goes to show you that it isn't all that simple and clear.
oops, I got to thinking in Pascal mode and didn't quite make the switch.
|>
|> > would print out the value of the first element in the array, while the C
|> > statement
|> >
|> > printf("%f\n",mine['a']);
|> >
|> > would print out some weird value from the 97th position of an array which
|> > only contains 26 elements. It would not complain, hiccup, warn, or
|> > otherwize help you find your error.
|> > you have to write
|>
|> You need to get a better compiler. Mine responds to the above with the
|> message:
|>
|> test.c 7 Warning 83: reference beyond object size
|>
|> <mike
What compiler are you using?
#include <stdlib.h>
#include <stdio.h>
typedef float mytype[26];
main()
{ mytype mine;
printf("%f\n",mine['a']);
}
I just tried it on 6 different C compilers. None of them gave any sort of
warning. C does not do range checking. If your C compiler complains, then
it is not a standard C compiler. Not only does it compile, it also runs
without reporting a run time error. No language of the Pascal family would
let such an obvious error slip by unless the programmer specifically requested
it. See if you get a warning on this piece of code:
#include <stdlib.h>
#include <stdio.h>
typedef float mytype[26];
main()
{ mytype mine;
char tm = `a`;
printf("%f\n",mine[tm]);
}
--
Larry D. Pyeatt The views expressed here are not
Internet : pyeatt@texaco.com those of my employer or of anyone
Voice : (713) 975-4056 that I know of with the possible
exception of myself.
Technical Details
Message-ID:
<1992Oct30.174207.22464@texhrc.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!pmafire!news.dell.com!swrinde!zaphod.mps.ohio-state.edu!menudo.uh.edu!nuchat!texhrc!texhrc!ak45ldpReferences:
<1992Oct18.131021.1165@kth.se> <SPACKMAN.92Oct28142448@disco-sol.dfki.uni-sb.de> <1992Oct29.163702.9849@texhrc.uucp> <mwm.2gwf@contessa.palo-alto.ca.us>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc Path: arc1-ca.pugleaf.net!sparky!uunet!pmafire!news.dell.com!swrinde!zaphod.mps.ohio-state.edu!menudo.uh.edu!nuchat!texhrc!texhrc!ak45ldp From: pyeatt@Texaco.com (Larry D. Pyeatt) Subject: Re: Robots... Message-ID: <1992Oct30.174207.22464@texhrc.uucp> Sender: news@texhrc.uucp Nntp-Posting-Host: microvax Organization: Texaco References: <1992Oct18.131021.1165@kth.se> <SPACKMAN.92Oct28142448@disco-sol.dfki.uni-sb.de> <1992Oct29.163702.9849@texhrc.uucp> <mwm.2gwf@contessa.palo-alto.ca.us> Date: Fri, 30 Oct 1992 17:42:07 GMT Lines: 72