Sujet : Re: Two questions on arrays with size defined by variables
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 09. Feb 2025, 18:18:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voao0d$o71o$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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