K
Kenny McCormack
Here is a commonly used technique, that will, of course, work fine on
any reasonably modern, normal hardware. But, does it pass the CLC test?
/* Assume well-formed input - of course, you can always break it by
* feeding it bad input */
struct foo { int field1, field2; char nl; } *bar;
char buffer[SOMENUMBERWHATEVERFLOATSYOURBOAT];
int main(void) {
bar = (struct foo *) buffer;
fgets(buffer,SOMENUMBERWHATEVERFLOATSYOURBOAT,stdin);
/* Now access the members of the struct (using, e.g., bar -> field1).
* Note that no actual struct was ever declared - we are using
* buffer as if it were the struct */
}
any reasonably modern, normal hardware. But, does it pass the CLC test?
/* Assume well-formed input - of course, you can always break it by
* feeding it bad input */
struct foo { int field1, field2; char nl; } *bar;
char buffer[SOMENUMBERWHATEVERFLOATSYOURBOAT];
int main(void) {
bar = (struct foo *) buffer;
fgets(buffer,SOMENUMBERWHATEVERFLOATSYOURBOAT,stdin);
/* Now access the members of the struct (using, e.g., bar -> field1).
* Note that no actual struct was ever declared - we are using
* buffer as if it were the struct */
}