开发者

What is the meaning of = {0}; in C?

开发者 https://www.devze.com 2023-03-02 10:25 出处:网络
I found the construct = {0}; in this C-code sample, found on tidy.sourceforge.net What is the rvalue of the statement and is it ANSI C?

I found the construct = {0}; in this C-code sample, found on tidy.sourceforge.net What is the rvalue of the statement and is it ANSI C?

#include <tidy.h>
#include <buffio.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char **argv )
{
   const char* input = "<title>Foo</title><p>Foo!";开发者_运维问答
   TidyBuffer output = {0};
   TidyBuffer errbuf = {0};


This initializes all fields in a struct, in your case TidyBuffer, to zeroes. The rule in C is that you can omit members in an initialization clause, and the rest will be initialized to zero. In C++, this is legal as well:

TidyBuffer output = {};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号