在 C99 中,如果之前申报了 >x
并且是类型 v2
,那么我可以写:
x = (v2) { 1, 2 };
此处 v2
是:
typedef struct {
int x;
int y;
} v2;
我能在C90做类似的事吗?
在 C99 中,如果之前申报了 >x
并且是类型 v2
,那么我可以写:
x = (v2) { 1, 2 };
此处 v2
是:
typedef struct {
int x;
int y;
} v2;
我能在C90做类似的事吗?
AFAIK, 复数字完全在C99中引入。 但是, 如果您在使用海合会时, 这个功能可以作为扩展。 引用 < a href=" http://gcc. gnu.org/ onlinedocs/ gcc/Compound- Literals.html" rel= “ nofollow noreferrerr" >GCC docs :
ISO C99 支持复合字面。 复合字面看起来像一个包含初始化器的铸件。 其值是铸件中指定类型的对象, 包含初始化器中指定的元素; 它是一个值 。 < 坚固> A 扩展, 海合会支持 C90 模式和 C/ 坚固的复合字面 。
关于海合会这一特点的另一份说明:
作为 GNU 扩展, GCC 允许通过复合字句初始化静态存储时间的物体( 在 ISO C99 中无法初始化, 因为初始化器不是一个常数 ) 。 如果复合字面类型和对象匹配, 则该天体只能使用括号封闭列表初始化。 复合字面和对象匹配的初始化器列表必须是固定的。 如果初始化对象的数组类型大小未知, 大小由复合字面大小决定 。
static struct foo x = (struct foo) {1, a , b }; static int y[] = (int []) {1, 2, 3}; static int z[] = (int [3]) {1};
以上各行相当于:
static struct foo x = {1, a , b }; static int y[] = {1, 2, 3}; static int z[] = {1, 0, 0};
在没有编译器扩展的 C90 中,您可以得到的最接近的 C90 将是 :
{
v2 temp = { 1, 2 };
x = temp;
}
可以压缩到一行或替换为宏。 (因为 C没有卫生宏, 但是, 您必须谨慎对待声明变量的宏, 当然。 )
否,这是一个 C99 特性。 然而, 某些编译者会允许它作为 C89 模式的扩展名, 例如 gcc 。
For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...
最好、最小、最快、开放的来源、C/C++ 3d 提供方(在3ds max模型的支持下),而不是通用公平市价,
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...
I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...
I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...
Is there anything other than DDD that will draw diagrams of my data structures like DDD does that runs on Linux? ddd is okay and runs, just kind of has an old klunky feeling to it, just wanted to ...
Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...