last day (16 days later) » 

16:39
5
Q: Rationale for requiring struct prefix in C

Paul J. LucasIn C, if you declare a struct like: struct point { int x, y; }; you also have to use struct when referring to point, e.g.: struct point p; // declare p as struct point because all struct, union, and enum names are in a distinct "tags" namespace. Yes, I know you can use a typedef to import...

Not sure, if this is really an RC.SE question as to me it's way more of a Langdef one, asking for the why in context of language design, doesn't it?
I agree w/ Raffzahn. Even if there is a satisfying historical explanation, an answer in the context of language design might be more interesting/useful. I think it should stay open because there might be an answer appropriate to here and one appropriate to pld, but you may want to ask over there.
@Raffzahn I did search this SE first and found questions like this, this, and this, and it doesn't look like anybody thought those were inappropriate. But sure, I can ask over at Langdev.
IIRC, K&R's code samples generally don't attempt to typedef struct types, so they may have thought it was stylistically better to have the struct keyword. So it could be that using typedef to avoid using struct was tolerated (to keep typedef general) but not encouraged.
@NateEldredge I’m looking for a definitive answer. (If it’s only stylistic, what other language(s) influenced Ritchie?)
16:39
It’s always felt to me like this is a uniformity consideration — use is the same as declaration (similar to declaration syntax mirroring expression syntax, as mentioned in TDotCL). But I’ve never seen anything authoritative specifically with regards to structs.
Like Larry Wall said: "Explicit is better than implicit"
@PaulJ.Lucas I think I didn't imply carelessness. RC.SE is being kind of perpendicular to all computer topics, isn't it? So there's quite some wiggling room mostly by the way a topic is looked at. In this case it seems being about use of name spaces (and marking them), something clearly a design choice for the language in addition you're asking explicit for the rational behind, which means the why that decision makes sense. That's clearly not a historical perspective, but a language design question. Wouldn't you agree that any answer is most likely one of language theory, not heritage?
@PaulJ.Lucas Also, pls. note, I din't vote for closure/move. I'm always amazed what pearls of wisdom RC.SE user do find - and wouldn't mind an answer bringing some historic context as well. Beside it being borderline, I firmly believe that a more language (theory) focused audience may be a way better source for a reasonable explanation of pro and con of the decision made for the struct keyword.
@Raffzahn Someone thinks that typedef wasn't in the embryonic versions of C, which means that all types were started via a keyword — which means it makes parsing simpler. (I've asked if there's any evidence regarding typedef.)
I was tempted to answer 'because Algol 68', but that language doesn't have structure tags. Which suggests a different spin on this question: why are there structure tags when typedef does the job? typedef struct { ... } mar1lyn
@dave Well, yeah. But K&R doesn't really use typedef for struct anywhere, so it seems like Ritchie preferred writing struct Foo.
16:39
struct was added around 1972. typedef (and enum for that matter) was added around 1979. (Maybe 1978 for the K&R C book)
@KelvinSherlock typedef was in K&R 1st ed. However, I found out that typedef was not in 6th Ed. Unix, but arrived in the 7th Ed.
So I guess that's your answer, Absent typedef, every declaration, apart from function definitions which must be at file level, starts with a keyword.
@dave Well, it's looking likely. Ideally, I'd like something more definitive. Now that you mention it, functions are the odd thing out since, originally, if a function returned int, the int could be omitted, so the parser would come across an unknown identifier and infer it was a function because of the ( I suppose.
As Raffzahn said, there was no typedef in the beginning. My first contact with C was on a System II Unix on a Fortune 32:16 machine and its compiler didn't have typedef.
16:39
@TobySpeight Read the first 2 comments. I was specifically encouraged to post the question there also.

  last day (16 days later) »