static-array

Difference between char and char[1]

非 Y 不嫁゛ 提交于 2019-11-29 22:47:45
In C++ what is the difference (if any) between using char and char[1]. examples: struct SomeStruct { char x; char y[1]; }; Do the same reasons follow for unsigned char? The main difference is just the syntax you use to access your one char. By "access" I mean, act upon it using the various operators in the language, most or all of which do different things when applied to a char compared with a char array. This makes it sound as if x and y are almost entirely different. If fact they both "consist of" one char, but that char has been represented in a very different way. The implementation could

Count the number of elements in an array in C [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-29 21:11:21
问题 This question already has answers here : size of array in c (6 answers) Closed 6 years ago . How can I obtain the number of elements present in an integer array in C after the array is passed to a function? The following code doesn't work. size=sizeof(array)/sizeof(array[0]); 回答1: In C, you can only get the size of statically allocated arrays, i.e. int array[10]; size = sizeof(array) / sizeof(int); would give 10. If your array is declared or passed as int* array , there is no way to determine

static arrays defined with unspecified size, empty brackets?

让人想犯罪 __ 提交于 2019-11-29 06:40:52
For the C++ code fragment below: class Foo { int a[]; // no error }; int a[]; // error: storage size of 'a' isn't known void bar() { int a[]; // error: storage size of 'a' isn't known } why isn't the member variable causing an error too? and what is the meaning of this member variable? I'm using gcc version 3.4.5 (mingw-vista special) through CodeBlocks 8.02. On Visual Studio Express 2008 - Microsoft(R) C/C++ Optimizing Compiler 15.00.30729.01 for 80x86, I got the following messages: class Foo { int a[]; // warning C4200: nonstandard extension used : zero-sized array in struct/union - Cannot

how to extract the name attribute from string array?

删除回忆录丶 提交于 2019-11-27 14:26:51
Hi I build a quiz application. I have the following (values/)question.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="question"> <item name="correct">A</item> <item name="wrong">B</item> <item name="wrong">C</item> <item name="wrong">D</item> </string-array> </resources> I would like to have a question with four possible answers but when i retrieve my answers in Java.. I don't know which answer is correct. So I decided to use name attribute in the item tags to pass a value of 'correct' or 'wrong' answer. Is there anyway to get the name along with the tag value?

Programmatically create static arrays at compile time in C++

Deadly 提交于 2019-11-26 06:09:33
One can define a static array at compile time as follows: const std::size_t size = 5; unsigned int list[size] = { 1, 2, 3, 4, 5 }; Question 1 - Is it possible by using various kinds of metaprogramming techniques to assign these values "programmatically" at compile time? Question 2 - Assuming all the values in the array are to be the same barr a few, is it possible to selectively assign values at compile time in a programmatic manner? eg: const std::size_t size = 7; unsigned int list[size] = { 0, 0, 2, 3, 0, 0, 0 }; Solutions using C++0x are welcome The array may be quite large, few hundred

Programmatically create static arrays at compile time in C++

感情迁移 提交于 2019-11-26 01:57:11
问题 One can define a static array at compile time as follows: const std::size_t size = 5; unsigned int list[size] = { 1, 2, 3, 4, 5 }; Question 1 - Is it possible by using various kinds of metaprogramming techniques to assign these values \"programmatically\" at compile time? Question 2 - Assuming all the values in the array are to be the same barr a few, is it possible to selectively assign values at compile time in a programmatic manner? eg: const std::size_t size = 7; unsigned int list[size] =