Re: How does Pi get its t

Since the compiler can warn or error for if(a=b), the reversal isn’t necessary.

It’s part of the C language. Personally I’d reject it in a code review, but compiler writers don’t really have any choice about supporting it.

Reply to
Richard Kettlewell
Loading thread data ...

Sure. I do wonder what funny substance K and R were smoking when they came up with 5[x] as a valid C syntax - they were definitely having a laugh. I suppose you could say that at pointer level, you are specifying a pointer of value (5*sizeof(int) + &x) for both 5[x] and x[5], but the latter is a damn sight more meaningful.

Reply to
NY

That makes my brain hurt. But is it syntactically legal? i is being used as an array (a pointer) on the RHS but as an integer on the LHS. And vice versa for j. I wonder how you would declare i and j so the code would actually compile.

Even k = ++i[j++] takes some fathoming: you take the value of i[j], increment it by 1 and assign it to k, and then increment j. I think... Definitely comes into the category of Too Clever By Three Quarters.

And as for that mass of apparently-random characters which forms a program that prints out the Twelve Days of Christmas - I haven't got the foggiest how that works.

Reply to
NY

How many characters were significant in a variable name in that dialect? For the Microsoft BASIC implementations you'd find on nearly everything on this side of the puddle, only the first two characters are significant. Attempting to obfuscate code by naming a couple of strings SCOTT1$ and SCOTT2$ will fail as they're both treated the same as SC$.

Reply to
scott

i[j] is just syntatic sugar for *(i+j) which is the same as *(j+i) (because addition is commutative) which is j[i] - IOW 3[x] is the same as x[3].

Reply to
Ahem A Rivet's Shot

They came up with x[y] as syntactic sugar for *(x+y) - they could have left it out without reducing the scope of what could be done with C.

The compiler converts 5[x] into *(5+x) becuase that's the language definition and performs pointer arithmetic. It's more of an unintended consequence of keeping things simple than a deliberate design decision.

Anyway why is "3rd of array" less meaningful than "array position

3" ?
Reply to
Ahem A Rivet's Shot

On a sunny day (Thu, 17 Feb 2022 07:15:59 +0000) it happened Ahem A Rivet's Shot snipped-for-privacy@eircom.net wrote in snipped-for-privacy@eircom.net:

If you put it that way OK. But somebody was moaning lately in an other groups that multi-dimensional arrays did not work in C. So just for fun I did this in xflir recently:

header: char input_frame_data[Y_PIXELS][X_PIXELS][3];

code: ... input_frame_data[y][x][0] = red; input_frame_data[y][x][1] = green; input_frame_data[y][x][2] = blue; ...

Works perfectly :-) How would you write that in that other notation?

Reply to
Jan Panteltje

It follows from the a[b] = *(a+b), which is not a complicated idea, and is a natural one given the code it generates.

Reply to
Richard Kettlewell

Oh yes they do :)

I wouldn't, it doesn't work for multi-dimensional arrays because the syntactic sugar is rather more complex.

Reply to
Ahem A Rivet's Shot

It’s syntactically legal. 'int i, *j;' would make it compile.

But it has no meaning. There’s no sequence point between the read of j on the left hand side and the change on the right hand side, so it violates a constraint in the language spec:

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

(C99 text, but later versions have what looks like effectively the same rule.)

Reply to
Richard Kettlewell

Surely the only appropriate response to thsat sort of statement is 'Prove it or shut up'.

IOW the moaner must show compilable, runnable code that illustrates the problem. If they can't or won't do that they get rubbished.

That's a good illustration of how to answer that sort of nonsense.

See also

formatting link

Creating an SSCCE is a good suggestion to make in this sort of argument. Its also very useful when you're helping someone (or yourself) to fix a tricky problem because often just defining it as an SSCCE will help you see the solution.

FWIW I first heard of the SSCCE in connection with writing Java but I think it can be usefully applied to any programming or scripting language.

Reply to
Martin Gregorie

There were actually 2 more books that were helpful to me, first of all for the hardware interfacing: Microprocessor interfacing techniques by Rodnay Zaks ea Publication date 1979

And some Unix book I bought when working at a linear accelerator here, they had a PDP? and it fascinated me. Was mainly doing hardware back then. Nice team, you were allowed some time for personal research, I designed a video digitizer, when was it 1977 or 1978? When I demonstrated it somebody told me "Did you know there is now a chip that can do all that?" hehe, indeed there was. But few considered sending video over a phone line back then. When I installed SLS Linux many years later on my PC all I had to do was lookup that Unix book and I was good to go.

Reply to
Jan Panteltje

Codepen is a common way of doing that for html+css+js but there is an equivalent for C, C++, C# etc

formatting link
Reply to
Andy Burns

Yep undefined behaviour.

Reply to
Ahem A Rivet's Shot

On Wed, 16 Feb 2022 22:32:53 -0000, "NY" snipped-for-privacy@privacy.invalid declaimed the following:

I'd object to it just on the basis that it is ambiguous -- depending upon what order the compiler computes the subscripted terms. Did the compiler determine/cache the address for j[i] first, and then do the increment/subscripts on the right side... Did it compute the right side first before applying the values to the left, ... etc.

Reply to
Dennis Lee Bieber

On Wed, 16 Feb 2022 23:26:32 GMT, snipped-for-privacy@alfter.diespammersdie.us declaimed the following:

As I recall, that tended to derive from Kemeny&Kurtz BASIC... <a..z>[<0..9>][$] (as I recall, original K&K BASIC didn't provide punctuation to differentiate integer<>float<>double, only the $ for string). One alphabetic followed by optional single digit, followed by optional string indicator. Also DIM statements allocated space for one element more than the number provided, as subscript 0 was valid.

Reply to
Dennis Lee Bieber

Ugh! Thankfully, the first interactive language I used was JEAN (JOSS Extensively Adapted for Nineteenhundred), which ran under the MINIMOP timesharing system, on ICL 1900s with teletypes connected via a uniplex or multiplex switch. JOSS itself was written for Rand's JOHNIAC computer

JEAN was nice to edit on a teletype since it used real line numbers: you could always insert another line between existing ones.

Its only real drawbacks were its single character variable names, so a program could only have 26 variables though they could be arrays, and its conditional syntax:

1.1 Type "Hello, World!" if X=5

which meant there was no 'else' branch.

Reply to
Martin Gregorie

My first introduction to computer programming was another ICL language, CESIL (Computer Education in Schools Instructive Language). That was at ICL's training centre, Beaumont, in Old Windsor (near the Bells of Ouzeley pub). It was in the scorching hot summer of 1976 and it was a toss-up between having the windows open so we didn't get *too* hot, and having them closed so we could hear the lecturer and he didn't get drowned out by the incoming and outgoing planes at Heathrow.

Only after a day of CESIL did we move on to BASIC. All our coding was done with pencil and squared coding sheets; these were then collected up and typed onto punched cards which were taken to another site nearby to be run on the computer, with listings returned the following day. Not very interactive! The only interactive time we got was on a teletype that was linked by acoustic coupler to a mainframe, on which we played the lunar-landing game.

I wrote an article for the school magazine about my experiences on the course, but some dimbo "corrected" CESIL to CECIL, so I was plagued by people saying "but Computer Education in Schools Instructive Language should have an S, not a C, in the middle".

It was a sign of the times that I opened the article with "The other day, my neighbour received an electricity bill for £376", as if that was a preposterous amount for a quarterly bill, which was due to a "computer error" that was probably operator error. Now a quarterly bill for £376 would be fairly low. How times change.

Reply to
NY

I missed CESIL by quite a few years. My introduction to programming was on my University's Elliott 503, a scientific computer that was programmed in Algol 60. Its main claims to fame were that it was one of the first semiconductor-based computers, its logic implemented entirely in discrete transistors (not an IC anywhere in it, so it occupied four very large grey cabinets). It was slightly faster at floating point arithmetic than it was at integer operations: after all, it WAS designed for scientific and engineering workloads.

After that I joined ICL's computer service bureau and learnt PLAN, the assembler used on all 1900 series machines, followed about a year later by COBOL. That was also where I discovered the JEAN language.

Reply to
Martin Gregorie

£376 in 1976 is £2880 today, says
formatting link
Reply to
A. Dumas

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.