0

in this code

void something () { /*something*/ }

are () separators or operators?

as i know in a function call () are operators:

something();

but in a function definition it would be a bit weird to have an operator, because operator in fact is a function and there is a function in a function definition?

can somebody explain this topic? what are the separators/punctuators exactly? they are tokens for the compiler to differentiate some part of the code? for example two statements?

/*statement1*/;
/*statement2*/;

;s are separating the statements from each other

so they are atomic syntactic elements for the compiler to understand the source code?

christo
  • 381
  • 2
  • 5

1 Answers1

0

Depends on the context.

() in C++ can fulfill both definitions at once (operator and separator), or only one at a time.

It is an operator, since () is literally defined as the function call operator in the language spec. Since an overloaded operator is still an operator, this is independent of the number of arguments being passed to it (zero, or several).

A separator in terms of (programming) languages is usually defined as one or two tokens that separate some language features from other language features. This is the case when you pass parameters to a function when it is called, since the brackets separate the function name from the function arguments. This is not the case if no argument argument is being passed during the function call, as there is nothing to separate. In this case, () would act as an operator, but not as a separator.

I also almost forgot to mention the fact that round brackets are also used in arithmetic to denote precedence (acting as separators, not operators).

Another example of () acting as operator, but not as a separator, would be a cast.

KUSH42
  • 552
  • 2
  • 13