Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: A string pointer to a static or dynamic string : how to free the dynamic one ? Date: Sun, 22 Jan 2023 13:07:51 -0800 Organization: None to speak of Lines: 74 Message-ID: <87wn5egtw8.fsf@nosuchdomain.example.com> References: <61d28ae0-d30f-47f7-adc2-bdadfd20d443n@googlegroups.com> <87a62bie22.fsf@nosuchdomain.example.com> <604d1f9c-51b9-4e7d-9c69-25b235a0eb5en@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="a96db803e771599752dfc0089ea20ee1"; logging-data="3426755"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rqil62TFqeGL+2LfDqL2K" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:4A0PPQcqf12VIzXGyFkXiT5tylc= sha1:0OV/mrDVBN+vYWQwQpMtWWT8OVw= Xref: csiph.com comp.lang.c++:88727 "R.Wieser" writes: > "Richard Damon" wrote in message > news:sbfzL.383809$iU59.50359@fx14.iad... >> On 1/22/23 9:40 AM, R.Wieser wrote: >>> If an address which is pointing to a sequence of characters is called a >>> "pointer to a string" - normally referred to as "a string pointer" - , >>> what should the variable which stores that addres be called ? >> >> A pointer to string (with type pointer to char). > > Yep. Both referred to with the exact same name. And that confuses the h*ll > outof someone who has to listen to someone talking about two different > things, but uses the same word for both. :-( > > Why do you think I asked ? > >> If you need to distinguish them, one is a value, and the other is a >> variable > > You know that, I know that. But listening to people talking about both > using the same "string pointer" name I have to wonder if they do ... If I understand you correctly, the two things you're referring to are the pointer *value* and an *object* of pointer type that holds that value. There's nothing special about pointers to strings here. The same confusion occurs with, for example, a pointer to an int (which is convenient, because we can discuss this without dragging C into the discussion). int n = 42; int* ptr = &n; The result of evaluating the expression `&n`, or the expression `ptr`, is a value of type `int*`. We commonly refer to this value as "a pointer" (or "an address"). The object named `ptr` is an object (variable) of type `int*`. We also commonly refer to this object as "a pointer" (though not as "an address"). Similarly we can refer either to `42` or to the object `n` as "an integer" or "an int". Usually this isn't a problem. In most contexts, the distinction between a value of some type and an object/variable that holds a value of some type either isn't important or is sufficiently clear from the context. For cases where the ambiguity is important, I find it useful to think of the word "pointer" (as well as "array", "integer", etc.) as an adjective rather than a noun. Thus we can refer to a *pointer value*, or a *pointer object", or a *pointer type*, or a *pointer expression*, all of which are clearly distinct concepts. I'll note that the C and C++ standards often do not use this level of precision (and in most cases they probably don't need to). For C's definition of a "pointer to a string", I'd say it refers to a *value* of pointer type. An object of type char* might have a current value that is a pointer to a string, but then after a value is assigned to it it might not. The state of being a "pointer to a string" applies to the value, not to the object that currently happens to hold such a value. I don't recall seeing a use of the term "pointer to a string" that was confusing because it could refer to either a value or an object. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */