4 ms·
https://github.com/dspinellis/unix-history-repo/blob/386BSD-0.0-Snapshot-Development/usr/src/sbin/reboot/reboot.c https://github.com/dspinellis/unix-history-rep
by self_awareness 8y ago
https://github.com/dspinellis/unix-history-repo/blob/386BSD-0.0-Snapshot-Development/usr/src/sbin/reboot/reboot.c https://github.com/dspinellis/unix-history-repo/blob/386BSD-...
void
dingdong()
{
/* RRRIIINNNGGG RRRIIINNNGGG */
}
setalarm(n)
int n;
{
signal(SIGALRM, dingdong);
alarm(n);
}
:)
- saghm 8y agoI haven't written C in a bit, so I'm a little confused about the second part of that snippet; is `setalarm` a macro? It doesn't look like a function declaration, as there's no return type, and the presence of `int n;` after `setalarm(n)` makes it seem like it would be shadowing `n` if `n` were a parameter rather than an argument (not to mention the fact that `int n;` is outside of the braces. Given that `setalarm` doesn't seem to be declared/defined anywhere in that file, can anyone who's a bit more familiar with the codebase point out to me what's going on here?
- jcelerier 8y agoit's pre-ANSI C function definition
- JdeBP 8y agoThere was a time when "I haven't written C in a bit" was a reason for immediately recognizing code such as this. (-:
- ktpsns 8y agoInterestingly, this way of function definitions is "still" the way subroutines/functions are defined in (modern/all time) Fortran (if one ignores the syntactic differences). Also, at "old" C, declarations only may come at the beginning of a block -- just as it still is with Fortran. Out of curiosity, is there any reason for the similiarity?
- ethhics 8y agoAt least for the declarations at the beginning of the block, that allows for very simple compiler design as it is very easy to split the code and data sections. Start off allocating space for all the variables it sees, and then when it reaches something not a declaration or definition, start emitting assembly.