Why can't I specify the size of an array in a struct with a const int variable?

Source: Internet
Author: User
typedef struct{INT Semid;    int counter; Char str[max_string];    }my_block_t;int Main () {my_block_t mybt;    Compile time error here??  Char str2[max_string];      There's nothing wrong here!! return 0;}

compiler different, the results of the compilation is also different, standard C does not support variable declaration declaration array size, but some fused C + + support variable declarations, but C + + is not recommended to write, the size of the array should be a constant, if you are not sure the size of the array is best or a vector, such as a container, the array is changed to Char str[8192], or it is set to a macro at the beginning define # define Max_string 8192 You can modify the array size as long as you modify this value, which is also a general method for writing code, which facilitates debugging of large code.

Why can't I specify the size of an array in a struct with a const int variable?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.