Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

semicolon after curly braces in c++

Tags:

c++

vtk

I have recently started working with the vtk package and I see this odd notation that they include ; after closing curly braces }. Here is an example from vtkUnstructuredGrid.h

// Description:
// Standard vtkDataSet API methods. See vtkDataSet for more information.
int GetDataObjectType() {return VTK_UNSTRUCTURED_GRID;};

It's not needed and QtCreator also correctly detects this by saying extra ; when parsing the code. I'm curious what could be the reason for this? Maybe readability?

like image 397
mmirzadeh Avatar asked May 17 '12 00:05

mmirzadeh


People also ask

What happens if we put semicolon after if statement in C?

Do not use a semicolon on the same line as an if , for , or while statement because it typically indicates programmer error and can result in unexpected behavior.

Do you need a semicolon after break in C?

As with all statements in C, the break statement should terminate with a semicolon ( ; ).

What does the semicolon do in C?

Semicolons are end statements in C. The Semicolon tells that the current statement has been terminated and other statements following are new statements.

Can you put a semicolon after a bracket?

Sometimes the parenthetical material is part of a longer sentence part that will be set off by a comma, colon, or semicolon. These pieces of punctuation always come after the parenthetical material, never before it or inside the parentheses.


1 Answers

As QtCreator correctly detects, that is definitely an extra semicolon that not only is useless, but can also cause compiler warnings and confusion.

For example GCC with the -Wpedantic flag will trigger:

warning: extra ';'

like image 141
Shoe Avatar answered Sep 22 '22 04:09

Shoe