by dammitcoetzee on 1/7/19, 5:12 AM with 50 comments
by jcranmer on 1/7/19, 6:11 AM
So one way to read C "gibberish" is to ignore the type at the beginning and parse the rest as an expression like a normal parse tree. First we take foo. Then we dereference it (so foo is a pointer). Next we call it as a function with no arguments (so foo is a pointer to a function that takes no arguments). Next, we dereference it again. Then we index into the result as an array. Finally, we reach the end, so we look at what the declared type and find that this type is an int. So foo is a pointer to a function that takes no arguments and returns a pointer to an array of 3 ints.
You can also use this to go backwards. What's the syntax for a function that takes an integer argument returns a pointer to an array of function pointers taking no arguments and returning integers? Well, we want to take foo, call it, dereference it, then index into an array, then dereference it again, then call it again, then return an int. Or int (* (* (foo)(int))[5])(void).
by ridiculous_fish on 1/7/19, 7:14 AM
It used to be a shared host with a PHP script shelling out to the cdecl executable, written in K&R C. Now it's that same executable running on AWS Lambda.
Yes Lambda really will run arbitrary ELF binaries.
by saagarjha on 1/7/19, 6:10 AM
by TorKlingberg on 1/7/19, 6:58 AM
by nurettin on 1/7/19, 7:56 AM
by Eli_P on 1/7/19, 9:31 AM
by pkaye on 1/7/19, 7:45 AM
by valerij on 1/7/19, 5:34 PM
std::funtion<foo(bar, baz)>
into foo(*)(bar, baz)
?
by mey on 1/7/19, 6:13 AM
by SidiousL on 1/7/19, 7:23 AM
int *pi;
Means that when I dereference the variable pi, I get an int. This also explains why int *pi, i;
declares `pi` as a pointer to `int` and `i` as an `int`. From this point of view it makes sense stylistically to put * near the variable.Declaration of array types is similar. For example,
int arr[10];
means that when I take an element of `arr`, I obtain an `int`. Hence, `arr` is an array of ints.Pointers to functions work the same way. For example,
int (*f)(char, double);
means that if I dereference the variable `f` and I evaluate it on a `char` and on a `double`, then I get an `int`. Hence, the type of `f` is "pointer to function which takes as arguments a char and a double and returns an int".by skookumchuck on 1/7/19, 7:12 AM
by Jerry2 on 1/7/19, 6:18 AM
((void(*)(void))0)();
by unnouinceput on 1/7/19, 8:15 AM
got: bad character '"'...apostrophe instead of double quote has the same result...well, I guess I expected too much