Deutsch English Français Italiano |
<20250209195711.00001bde@yahoo.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.lang.c Subject: Re: Two questions on arrays with size defined by variables Date: Sun, 9 Feb 2025 19:57:11 +0200 Organization: A noiseless patient Spider Lines: 45 Message-ID: <20250209195711.00001bde@yahoo.com> References: <vo9mns$gsd7$1@dont-email.me> <vo9nn3$gtph$1@dont-email.me> <vo9u0u$i0n8$1@dont-email.me> <20250209123918.0000754f@yahoo.com> <voao0d$o71o$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sun, 09 Feb 2025 18:57:11 +0100 (CET) Injection-Info: dont-email.me; posting-host="8e2d9f7cf4b47825ab2c863bbd44b8cd"; logging-data="802523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184ANJiv+mq4hnNKANnTx+MpA0Kwefc3pg=" Cancel-Lock: sha1:AdFilVC3hTTbQh77KtpxyRmcIVE= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 2805 On Sun, 9 Feb 2025 18:18:04 +0100 Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > On 09.02.2025 11:39, Michael S wrote: > > On Sun, 9 Feb 2025 10:54:36 +0100 > > Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > > [...] > > > > There is another problem in your code - it assigns string literal to > > non-const char*. It is legal, as far as 'C' Standard is concerned, > > but makes very little practical sense, because any attempt to > > assign to string literal through resulting pointer is UB. And not > > just a theoretical UB, but a real-world UB. > > This comment specifically draw my attention and made me nervous. > > You know, I'm rarely programming in plain "C", and while in C++ > I generally try to program in "const-correct" form Which, I suppose, is not easy. > I never make > use of 'const' in "C". - Unless the compiler complains about it, > but I don't recall it (ever?) did. > > In my test application I actually never assign string literals > or strings to any other string object (modulo the buffer that I > filled with a 'fgets'). I operate solely with pointers to 'argv' > elements and to the 'char buf[]' buffer data. > > Do you see any issue with that? > > Janis > I see no issues. Generally, due to absence of user-defined polymorphism, C does not have the type of ugly surprises with constness that make life of C++ programmers miserable. Still, behavior of string literals can be surprising. I would guess that if it was feasible to make a breaking changes, C89 would define type of string literals as 'const char*' rather than 'char*'. But breaking changes were not feasible.