Deutsch   English   Français   Italiano  
<voao0d$o71o$1@dont-email.me>

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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: Two questions on arrays with size defined by variables
Date: Sun, 9 Feb 2025 18:18:04 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <voao0d$o71o$1@dont-email.me>
References: <vo9mns$gsd7$1@dont-email.me> <vo9nn3$gtph$1@dont-email.me>
 <vo9u0u$i0n8$1@dont-email.me> <20250209123918.0000754f@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 09 Feb 2025 18:18:06 +0100 (CET)
Injection-Info: dont-email.me; posting-host="9f9c4a4d467cd7826f6af056aa0b049d";
	logging-data="793656"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+/V092PCl+j9SEQjZKD5vE"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:YVMnZ9mTygxlIcMt/VOHICFmPJc=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <20250209123918.0000754f@yahoo.com>
Bytes: 2252

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 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