Thursday, July 27, 2023

Digest for comp.lang.c++@googlegroups.com - 4 updates in 1 topic

wij <wyniijj5@gmail.com>: Jul 27 06:51AM -0700

I found char array can be initialized by string literal ! Is such coding correct?
 
--------------------------------------
int main() {
char tnam[]="tmpnamXXXXXX";
 
int fd=::mkstemp(tnam);
return 0;
}
 
g++ t.cpp -std=gnu++11
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Jul 27 07:01AM -0700

On Thursday, 27 July 2023 at 14:51:57 UTC+1, wij wrote:
> return 0;
> }
 
> g++ t.cpp -std=gnu++11
 
Yes, that's fine.
char modifable[] = "This string can be modiifed";
const char *constant = "This string shouldn't be modified";
Tony Oliver <guinness.tony@gmail.com>: Jul 27 07:14AM -0700

On Thursday, 27 July 2023 at 14:51:57 UTC+1, wij wrote:
> return 0;
> }
 
> g++ t.cpp -std=gnu++11
 
N3096: 6.7.10 Initialization
 
15 - An array of character type may be initialized by a character string
literalor UTF-8 string literal, optionally enclosed in braces.
Successive bytes of the string literal (including the terminating null
character if there is room or if the array is of unknown size) initialize
the elements of the array.
"Alf P. Steinbach" <alf.p.steinbach@gmail.com>: Jul 27 07:36PM +0200

On 2023-07-27 4:14 PM, Tony Oliver wrote:
> Successive bytes of the string literal (including the terminating null
> character if there is room or if the array is of unknown size) initialize
> the elements of the array.
 
That appears to be the C standard, while this is a C++ group.
 
The languages are not the same.
 
C++ requires that there is room for a terminating zero.
 
 
- Alf
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: