3 ms·
Why do they need both > uint64_t SIZEOFUINT64 = 8; // in bytes and > SIZEOFUINT64 = (uint64_t) ((uint64_t*) SELFIE_URL + 1) - (uint64_t) SELFIE_URL;
by tromp 4y ago
Why do they need both
> uint64_t SIZEOFUINT64 = 8; // in bytes
and
> SIZEOFUINT64 = (uint64_t) ((uint64_t*) SELFIE_URL + 1) - (uint64_t) SELFIE_URL;
in init_library() ?
- forkerenok 4y agoThe first one looks like a declaration in the global scope with a sane default, the latter is determining the actual size. Haven't done C in a long long time, so I may be talking out of my ass.
- pkphilip 4y agoYour take seems accurate. That is my reading as well
- sph 4y agoI don't believe it one bit that you haven't done C in 2^64 seconds. EDIT: technically 2^63-1 seconds.
- jay-barronville 4y agoLol! I actually chuckled at this. I completely missed that.
- Someone 4y agoI think it’s more likely this is a minor/latent bug. Initializing the value and later assigning it a new value runs the risk of having some code that uses the value of one expression and other code that uses the value (presumedly/hopefully identical to the former) of another expression. That’s not a risk you want to take. The name also doesn’t give me an indication they considered making the code agnostic as to the size of that variable.
- jay-barronville 4y agoFrom reading the code [1], both aren't needed; the `SIZEOFUINT64 = (uint64_t) ((uint64_t*) SELFIE_URL + 1) - (uint64_t) SELFIE_URL;` statement is the value that always ends up being used (once the library is initialized). An optimizing compiler would likely optimize the calculation away anyway. My guess is that it's predefined at the top simply for clarity and verbosity's sake (remember that this is built for educational purposes). [1]: https://github.com/cksystemsteaching/selfie/blob/5de675a0f08613adab2315d50ce7c2db2079005d/selfie.c#L308 https://github.com/cksystemsteaching/selfie/blob/5de675a0f08...
- unwind 4y agoIt's really scary and I struggle to understand what is wrong with just const size_t SIZEOFUINT64 = sizeof (uint64_t);
- ufo 4y agoTheir compiler doesn't support sizeof. Maybe it's like that to ease bootstrapping?
- jay-barronville 4y agoI think it's because their subset of C [1], which they call C Star (C*), doesn't support the `sizeof` operator. Since Selfie is supposed to be able to compile itself, it seems they've restricted the used grammar to the subset supported by C*. [1]: https://github.com/cksystemsteaching/selfie/blob/50b5fec83785d9619d8d5a3773f3482dcac5f4f1/grammar.md https://github.com/cksystemsteaching/selfie/blob/50b5fec8378...
- unwind 4y agoAah of course. Didn't read that far. Thanks.
- pjmlp 4y agoC Star (C*) ?!? Oh, well. https://en.wikipedia.org/wiki/C https://en.wikipedia.org/wiki/C* => "It was developed in 1987 as an alternative language to Lisp and CM-Fortran for the Connection Machine CM-2 and above. The language C* adds to C a "domain" data type and a selection statement for parallel execution in domains. "