Sebastian
Sebastian

Reputation: 6493

What is the meaning of = {0}; in 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};

Upvotes: 2

Views: 431

Answers (1)

Frederik Slijkerman
Frederik Slijkerman

Reputation: 6529

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 = {};

Upvotes: 5

Related Questions