Re: A: a new bug to old plain C

Henrik Holst via Gcc-help <[email protected]>
Newsgroups gmane.comp.gcc.help
Message-ID <CAGwK9dy-eXAFWYMM6x4HqU4zrCq_=SuKm3+iSj-ExKDsj8Werg@mail.gmail.com>
Den sön 7 dec. 2025 kl 23:46 skrev Segher Boessenkool <
[email protected]>:

> On Sun, Dec 07, 2025 at 01:49:46PM -0800, Andrey Tarasevich wrote:
> > > > There are lots and lots of
> > > > conversions in C that are only available through _explicit_ _casts_
> > >
> > > Where "lots and lots" means "exactly zero": you can always do an
> > > ssignment to something with an appropriate type.
> >
> > I'm not sure what you are trying to say here. Constraints of assignment
> in C are exactly
> > as strict as constraints of initialization. (In fact, the later are
> defined in the standard
> > simply by a direct reference to the former.)
>
> I am saying that explicit casts (which means using a cast operator) are
> never ever required.
>

yes they are:

int main (int argc, char **argv)
{
  struct a a;
  struct b b = a;

test.c: In function ‘main’:
test.c:1308:22: error: invalid initializer
 1308 |         struct b b = a;

/HH

>
> And no, you never have to go via pointer stuff either.  Just assign to
> something that actually holds the type you are trying to convert to.
> Don't hide aything!  It won't help you!
>
>
> Segher
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.