|
Good one! I deserved that.
How did you come up with S. Vigna?
|
|
|
|
|
Well,
I searched for the code snippit and found it in the NE editor source code[^] dated 1998.
Best Wishes,
-David Delaune
|
|
|
|
|
Very good! I like ne and it is an excellent editor! My hat is off to Sebastian. I was using it back in the late 1990's and adapted to run on AIX when I was doing work out of Chicago in Australia and London over a 9600BPS links. I had cause to want to run it recently for a project and resurrected it.
I love it's ease of use and functionality, but the code is difficult to follow.
I would love to meet Sebastian--he must be one brilliant son of a gun!
|
|
|
|
|
Just out of curiosity, how did you search? And where?
|
|
|
|
|
|
I agree with you that the code is just a pain.
Quote: Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers!
I would. It better. If it's not, it's not C spec and the documentation better have that in big red flashing letters.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Oh, ever hear of Caché? (The "database".)
Its not-quite-SQL language doesn't honor order-of-operations! (But it's faaaasssst!)
|
|
|
|
|
that seems kind of pointless. How can I tell what it's doing? oh never mind. it's just silly. i don't even want to know.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Quote: Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! That's given.
However I agree with you, it is difficult to understand such a code.
|
|
|
|
|
"Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers!"
Evaluation order must stay the same as it is part of the C language spec since its inception!
|
|
|
|
|
Both the operator precedence (and thus the order of evaluation) and short circuiting are part of the C language definition and is not compiler dependent. The compiler can only reorder the expression during optimization if it can ensure that it does not change the result.
It is quite safe to rely upon. This expression already has a sufficient number of parentheses, more just makes it less readable. I'm not even sure where you would even put extra parentheses.
|
|
|
|
|
I read the spec and it supposed to be standard across all compilers but I have lost count of how many OS and application bugs of that type I have had to chase.
As patbob pointed out, it is the pre-decrement that is worrisome. And the first couple of times I look at the code, I missed the "!".
To test this logic, I wrote a little program which (I think) simulates the original code results:
#include <stdio.h>
int testf(int rv, int a) {
return rv;
}
int main()
{
int value = 0;
for (int i = 0; i < 16; i++) {
printf("%2x = ", value);
int a = 0;
if (value & 8) printf("T"); else printf("F");
if (value & 4) printf("T"); else printf("F");
if (value & 2) printf("T"); else printf("F");
if (value & 1) printf("T"); else printf("F");
printf(" = ");
if ( (value & 8) && testf((value & 4), --a) || (value & 2) && testf((value & 1), --a))
printf("T %d", a);
else
printf("F %d", a);
value++;
printf("\n");
}
return(0);
}
The results are:
0 = FFFF = F 0
1 = FFFT = F 0
2 = FFTF = F -1
3 = FFTT = T -1
4 = FTFF = F 0
5 = FTFT = F 0
6 = FTTF = F -1
7 = FTTT = T -1
8 = TFFF = F -1
9 = TFFT = F -1
a = TFTF = F -2
b = TFTT = T -2
c = TTFF = T -1
d = TTFT = T -1
e = TTTF = T -1
f = TTTT = T -1
|
|
|
|
|
I stand corrected. I missed the double decrement (sorry, it has been a long and intense semester, I'm not fully back up to speed). Multiple increments or decrements of the same variable are undefined according to the standard. Sequencing might make it OK, but that can't be assured. There might be a corner of the standard that allows it with the sequencing, but I wouldn't assume that it is legal.
The intent of the original logic appears to be: Given a key r, to search two hash tables, in order. If a match is found, then r should be assigned the index returned from the matching hash table, reduced by one for indexing into the "commands" table.
The difference between your code and the original is that the original reassigns "a" after the "or". That is intended to wipe out any previous changes to "a". Your code does not do that so it will potentially get a double increment.
To match the intent of the original, one of the following tweaks could be used (minor formatting applied -- note that I use "and", "or" and "not" to reduce errors caused by mixing up & and &&, or by mixing up | and ||).
action a;
if ((a = hash_table[r]) and not cmdcmp(commands[--a].name, p)
r = a;
else if (a = short_hash_table[r]) and not cmdcmp(commands[--a].short_name, p))
r = a;
else
r = -1; This has an extra assignment -- that the compiler can optimize away by merging identical blocks. A more interesting alternative is
action a;
if ((a = hash_table[r]) and (a = a - 1, not cmdcmp(commands[a].name, p)) or
(a = short_hash_table[r]) and (a = a - 1, not cmdcmp(commands[a].short_name, p)))
r = a;
else
r = -1; which makes use of the comma operator. Decrement is not directly used, but the compiler will generate the same code, but lifted before evaluating the function call's parameters.
|
|
|
|
|
You're right--I missed that second assignment. Thank you.
And this kinda goes to my point: Well written code should be easily comprehensible to us mere mortals.
While the original code brilliantly takes advantage C language capabilities, it lends itself to errors of understanding, especially when a person doing maintenance is under pressure to fix a problem. (We lose approximately 20% of our thinking capabilities under pressure and, under sufficient pressure, the logical, thinking part of our shuts down.)
|
|
|
|
|
You are absolutely correct. Both of us missed parts of the expression. That is why I would more likely use the first variant I gave rather than the second one. And probably would write neither in practice, but without a wider context can't say what I would actually write. It would probably involve some restructuring.
|
|
|
|
|
rjmoses wrote: Somebody sure put a lot of faith that the order of evaluation, especially short-circuit evaluation, would remain the same across compilers! Order of evaluation and the short-circuit behavior is (or at least, used to be) part of the C language definition.
It's the use of variable assignment and pre-decrement operator in the (short-circuited) if statement that worries me. Regardless, I hope you rewrote it into something more maintainable.
|
|
|
|
|
I remember a demo where someone turned a for-loop into an until one (ptr->next instead of i++, next!=nil instead of i<=max and so on). My first reaction was "wow, that's clever". My second reaction was "you know how you f***ing hate it to debug clever code, especially if it's your own clever code from half a year ago".
|
|
|
|
|
After having received the anycubic mega-s and being really impressed with it, I found that I was wanting to rattle out maybe another small print, but the printer was busy doing something big, so basically tied up for the day (or over night). I started looking around for a 2nd smaller printer, one of these nano/mini ones that could print objects upto around 10cm cubed. The prices weren't far off the same price as my current printer, and by the time I added shipping to Cyprus, it just didn't make sense, so I didn't bother.....
Then I was in chat on a thread in Twitter, and someone posted a link to the printer I had already bought, on the manufacturers website and had mentioned the price, and I thought that it sounded slightly cheaper than normal and so out of curiosity I clicked the link and visited the site, and sure enough it was on sale $40 off. That is when I noticed they were having a pre-christmas sale.
I just started looking at all their models again, just because I was the site, and then I noticed their large Delta style Predator printer was reduced from $619 to $339 in the sale, but only available in Europe and Australia. I thought their shipping price to Cyprus would kill the savings. I added it to the basket and took it through the checkout process to see what they would charge for the shipping and well elephanting me it was FREE!
I really couldn't miss this, so paid with paypal and the exchange rate came out at 266ukp. So I consider this a birthday present to myself, seeing as that is next week!
Now, I knew this thing would be bigger than my current one, as the print volume is 370mm diameter by 455mm tall, but it wasn't until I looked at Youtube at the reviews that it really dawned on me how big.
I mean, it looks massive next to this guy....
Anycubic Predator 3D printer Review - YouTube
Good job I have a dead corner in the office at home that it can sit in!
Anyway, can't wait for it to arrive now, could job I'm heading home next week and it should be arriving around the same time.
|
|
|
|
|
Holy cr@p, that's big!
I'd have to remove stuff from my office just to get it in, and even then it'd be massive cat-bait unless I moved even more stuff out to give space for a box to put it in ...
Congrats on the free shipping though!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
As absolutely bitchin and "space age" 3d printing is. Compared to laser 2D printers it still seems primitive. Lots of plugging stuff and add on stuff to make it better. Reminds my of the early days of the personal computer like the Amiga heyday and the nerd clubs. I think someday we'll look back and snicker at the fiddlyness of it all.
Kick A$$ tugboats.
Toot toot!
|
|
|
|
|
Print me a cute lil car.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I think it could manage this one:
cute lil car - Google Search[^]
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Wow, that looks like what you get if you fart inside a Smart car.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
IMCDb.org: BMW Isetta 300 in "Family Matters, 1989-1998"[^]
Steve Urkel loved it
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|