Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Why does C allow structs to have a tag? Date: Sun, 11 Jul 2021 00:26:22 -0700 Organization: A noiseless patient Spider Lines: 41 Message-ID: <86a6mt8g69.fsf@linuxsc.com> References: <867dijb22a.fsf@linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="52e1adecb53146628fb5ee5c083fc413"; logging-data="8554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0KZctrRCusDhfXca9AF8icDnCuxYrHyQ=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:ENjIE0kUuVapKvQblckYNi1af0I= sha1:ozoFeZH7gtgEIYzxG/fqaoqsIa0= Xref: csiph.com comp.lang.c:161867 John Bode writes: > On 6/24/21 12:33 PM, Tim Rentsch wrote: > >> John Bode writes: >> >> [...] >> >>> To reiterate a point I make a lot - typedef on its own creates leaky >>> abstractions. If I need to know that I have to use the `.` or `->` >>> operator on something, I'd rather have it declared as `struct A foo;` or >>> `struct B *ptr;` instead of a type name that doesn't convey struct-ness >>> at all. Same reason I don't like it when people hide pointers behind >>> typedefs - I once spent half a day chasing my tail because somebody >>> created a typedef name for a pointer type and used that as a template >>> parameter for a vector in C++, such that when I was using an iterator >>> I needed to write >>> >>> (*it)->do_something(); >>> >>> However, since the typedef name didn't indicate pointer-ness *at all*, I >>> wound up writing >>> >>> it->do_something(); >>> >>> and g++ vomited up hundreds of incomprehensible error messages that >>> basically boiled down to "you need to use a * here, dummy". >> >> Sounds to me like the culprit is C++, not typedefs. > > g++ doesn't handle errors in template parameters very well and generates > a *lot* of hard-to-follow error messages for relatively simple mistakes. > And at the time I was still relatively inexperienced with C++, which > didn't help. > > But the typedef name (or, more properly, the incomplete and leaky > abstraction introduced by that typedef name) was the actual culprit. > [...] I stand by my earlier claim that the culprit here is C++ rather than typedefs.