Can structure always end with a semicolon in C -


here have 2 structures. first is:

struct complex {     double real, imaginary; }; 

which know must end semicolon.

but 1 function

struct complex add_complex(struct complex c1, struct complex c2) {     struct complex c3;     c3.real = c1.real + c2.real;     c3.imaginary = c1.imaginary + c2.imaginary;     return c3; } 

here if don't include semicolon @ end, compiler generate no error. why?

a structure definition must have semicolon @ end. you'd compiler error if removed ; struct complex definition.

the second 1 (add_complex)isn't structure definition, it's function returning structure. functions don't have semicolons @ end of them.

  • i mean, if write struct complex add_complex() { }; 1 true. why?

it being "ok", depends on compiler. compilers i've used (gcc , micosoft's example) allow this, can made display warning/error correct flags (adding -pedantic gcc give: warning: iso c not allow ‘;’ outside of function [-pedantic] , can add -werror) turn error.)


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -