Home > Back-end >  Compound literals have common understanding?
Compound literals have common understanding?

Time:01-30

Please see my popular understanding is correct, as follows,
One is in memory of the 2 x2 int array, no name, only address, also need to record in time to the pointer variable, or throw into a function's parameter,
One is in memory of the 2 x2 int array, name is an array,

So popular said, the array of compound literal is nameless?

 
Int main () {
Int * p=(int [2] [2]) {
{10, 20},
{30, 40}
};
An int array [2], [2]={
{10, 20},
{30, 40}
};
return 0;
}

CodePudding user response:

Following this code, is a nameless compound literals, generate only god knows where it is later, like throwing the drift bottle into the sea, is it?

 int main () {
(int [2] [2]) {
{10, 20},
{30, 40}
};
return 0;
}

CodePudding user response:

According to your topic, I found a good magic,
Int main ()
{

(int [3]) {7,8,9};
Printf (" % d \ t ", * $S1);
Printf (" % d \ t ", * $S1 + 1);
Printf (" % d \ t ", * $S1 + 2);
return 0;
}
/////
7
8
9
////
How to have such a strange thing? You can try the TC compilation,, whether can only VS can compile,

CodePudding user response:

Is not necessarily the array, also can be a structure, or even structure arrays,

CodePudding user response:

Compound literals is not only an array
Line structure also
A single int or
Create an anonymous object that understand no problem
Limited array is superfluous idea

CodePudding user response:

refer to the second floor UIUI response:
according to your topic, I found a good magic,
Int main ()
{

(int [3]) {7,8,9};
Printf (" % d \ t ", * $S1);
Printf (" % d \ t ", * $S1 + 1);
Printf (" % d \ t ", * $S1 + 2);
return 0;
}
/////
7
8
9
////
How to have such a strange thing? You can try the TC compilation,, whether can only VS can compile,


What is your these $S1? Haven't wait until the compilation, Clion IDE scarlet letter error,

CodePudding user response:

reference 4 floor lin5161678 response:
composite literal is not only an array
Line structure also
A single int or
Create an anonymous object that understand no problem
Limited array is superfluous ideas


A single int probably cannot be called composite, a single and compound is opposite,

CodePudding user response:

reference 5 floor qq_16774199 reply:
Quote: refer to the second floor UIUI response:
according to your topic, I found a good magic,
Int main ()
{

(int [3]) {7,8,9};
Printf (" % d \ t ", * $S1);
Printf (" % d \ t ", * $S1 + 1);
Printf (" % d \ t ", * $S1 + 2);
return 0;
}
/////
7
8
9
////
How to have such a strange thing? You can try the TC compilation,, whether can only VS can compile,


What is your these $S1? Haven't wait until the compilation, Clion IDE scarlet letter error,
compiler extensions known as dialect no need to worry about unimportant things

CodePudding user response:

VS2019 can compile ah,,,,

CodePudding user response:

# 2 only vc + + to compile the code, and must be as compiled C code, C + + Builder, GCC, Intel C + + are not compile,

CodePudding user response:

Structure, union, array (different types of arrays)

CodePudding user response:

refer to 6th floor qq_16774199 response:
Quote: refer to 4th floor lin5161678 response:
composite literal is not only an array
Line structure also
A single int or
Create an anonymous object that understand no problem
Limited array is superfluous ideas


A single int probably cannot be called composite, a single and composite are antonyms,

This is the C language term is not a Chinese reading comprehension
Even the practice of Chinese reading comprehension you also belongs to a peer, please
Not a single int?
Why not
Have you ever seen a standard
You actually write code tested
Don't do anything with open mouth is not? Spoken language programming or imagine programming?

CodePudding user response:

C standard except VLA inside of any complete object type can make composite literal
Int completely meets the requirements

CodePudding user response:

Simple understanding is that temporary anonymous objects
 struct A {
int a;
};
Int main (int arg c, const char * argv []) {
A. A={5};//the anonymous object memory format and data type on the left side of the same
A, b={5} (struct A);//this and the above are equivalent
Printf (" % d \ n ", a.a);
Printf (" % d \ n ", b.a);
//printf (" % p \ n ", & amp; {5} (struct (A)));//here will be prompted to {5} is A temporary object (struct A)

Int c=6;//this is common literal (it is a constant)
Int d=(int) {6};//this is a compound literal, this and the above ordinary literal equivalence (namely effect, so can use a single int, just compound literal is a temporary object)
Printf (" % d \ n ", c);
Printf (" % d \ n ", d);
}

CodePudding user response:

reference 13 floor qybao reply:
simple understanding is that temporary anonymous objects
 struct A {
int a;
};
Int main (int arg c, const char * argv []) {
A. A={5};//the anonymous object memory format and data type on the left side of the same
A, b={5} (struct A);//this and the above are equivalent
Printf (" % d \ n ", a.a);
Printf (" % d \ n ", b.a);
//printf (" % p \ n ", & amp; {5} (struct (A)));//here will be prompted to {5} is A temporary object (struct A)

Int c=6;//this is common literal (it is a constant)
Int d=(int) {6};//this is a compound literal, this and the above ordinary literal equivalence (namely effect, so can use a single int, just compound literal is a temporary object)
Printf (" % d \ n ", c);
Printf (" % d \ n ", d);
}
is not a temporary

You can always add something wrong
Is the anonymous objects not so much
Is not a temporary don't limit is array
There is no other at sixes and sevens prefix
Simple anonymous objects can
  • Related