Rendered at 03:27:30 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
chasil 1 hours ago [-]
I just rebuilt a core program that talks to my UNIVAC OS2200 CITA and my VAX ACMS from Linux.
I built this first as a 32-bit binary, and there was noise that I had to cut with a substr function.
In the rebuilding with my MinGW 64-bit Windows cross compiler on Oracle Linux, I had to mine function prototypes out of all the code for exactly this reason.
'for those unaware: c89 has a cool "feature" where, if you try to call a function which doesn't exist, rather than erroring out, the function is implicitly declared as a function with unspecified parameters returning int.'
I'm not testing this, because that is agony.
I'm leaving them a working build, and retiring this month.
This code was written by the living and the dead, and my stewardship is finished. I do not envy the poor soul who must test this.
It was ashes when I excavated it myself. A hat tip to those who have gone before.
bellowsgulch 4 days ago [-]
All the weird stuff I have read about C or C++ doing over the years could be summed up with “Well… don’t do that.”
Like almost without fail. I can’t even think of how you’d end up in a scenario like this because a compiler would complain before letting you use an undefined implicit declaration.
bitbasher 3 days ago [-]
That doesn't make it any less interesting :)
kevin_thibedeau 2 hours ago [-]
> f[...]
It is illegal to perform pointer arithmetic on function pointers. They are not necessarily interchangeable with data pointers. Clang is wrong.
phire 1 hours ago [-]
In c89, there doesn't seem to be any distinction between pointer to functions and pointer to data.
Do you know what c89 does explicitly say is undefined? Any pointer arithmetic at all (or array subscripting) for pointers are not pointing to a member of an array. It's already invalid to do pointer arithmetic a pointer to a struct.
Not that it matters for this. This isn't doing pointer arithmetic, f is simply the identifier for the array of sizeof(f) ints that make up the function argument. The identifier is optional for a function declaration.
kevin_thibedeau 48 minutes ago [-]
There is a distinction. Lisp machines do not allow function pointers to become data pointers. The C standard accounts for that. Function pointers also have special decay behavior unlike data pointers. You can chain an unlimited number of '*'s and still get a valid function pointer.
int f(int x) { return x + 1; }
int main(int argc, char *argv[]) {
int (*fp)(int) = f;
printf("Answer: %d\n", fp(39) + (****fp)(1));
return 0;
}
guenthert 4 days ago [-]
"because the problematic behavior was removed from the standard over 27 years ago, we'll never have closure on what the intended interpretation is."
Obsolete standard turns out to be insufficiently strict, news at 11.
I built this first as a 32-bit binary, and there was noise that I had to cut with a substr function.
In the rebuilding with my MinGW 64-bit Windows cross compiler on Oracle Linux, I had to mine function prototypes out of all the code for exactly this reason.
'for those unaware: c89 has a cool "feature" where, if you try to call a function which doesn't exist, rather than erroring out, the function is implicitly declared as a function with unspecified parameters returning int.'
I'm not testing this, because that is agony.
I'm leaving them a working build, and retiring this month.
This code was written by the living and the dead, and my stewardship is finished. I do not envy the poor soul who must test this.
It was ashes when I excavated it myself. A hat tip to those who have gone before.
Like almost without fail. I can’t even think of how you’d end up in a scenario like this because a compiler would complain before letting you use an undefined implicit declaration.
It is illegal to perform pointer arithmetic on function pointers. They are not necessarily interchangeable with data pointers. Clang is wrong.
Do you know what c89 does explicitly say is undefined? Any pointer arithmetic at all (or array subscripting) for pointers are not pointing to a member of an array. It's already invalid to do pointer arithmetic a pointer to a struct.
Not that it matters for this. This isn't doing pointer arithmetic, f is simply the identifier for the array of sizeof(f) ints that make up the function argument. The identifier is optional for a function declaration.
Obsolete standard turns out to be insufficiently strict, news at 11.
That's a nice bit of understated 90s design right there