Randomblue
Randomblue

Reputation: 116273

Does C have a concatenation operator?

This Verilog tutorial (see the table at the end) suggests that { } is a concatenation operator is C. I don't remember curly brackets as being an operator in C.

Is { } a concatenation operator in C?

Upvotes: 2

Views: 3983

Answers (7)

user4559909
user4559909

Reputation: 1

## is a concatenation operator....

Upvotes: -1

Jonathan Leffler
Jonathan Leffler

Reputation: 753555

No, in pure C, the braces are not a concatenation operator.

Note that the table of operators on the Verilog page includes a number of other 'non-C, non-C++' operators:

~&    nand
|     or
~|    nor
^     xor
^~    xnor
~^    xnor

Where the operators are the same as in C, they have the same meaning as in C. But there are operators in Verilog that are not in C (and, if that table is complete, operators in C that are not in Verilog).

Upvotes: 1

John Bode
John Bode

Reputation: 123448

From the linked tutorial:

To make life easier for us, nearly all operators (at least the ones in the list below) are exactly the same as their counterparts in the C programming language.

Emphasis mine. The exceptions are ~&, ~|, ~^, ^~, and {}.

Adjacent string literals are automatically concatenated:

char *str = "This is the first half " 
            "and this is the second half";

Anything involving a char buffer, though, requires a library function like strcat:

char buf[SOME_SIZE];
...
strcat(buf, "This is the first half ");
strcat(buf, "and this is the second half");

There is also the preprocessor token pasting operator ##, but the result must be a valid preprocessor token.

Upvotes: 3

ouah
ouah

Reputation: 145829

The only operator C has with { } is the ( ){ } operator which is the compound literal operator.

Upvotes: 1

ckruse
ckruse

Reputation: 9740

Depends. Curly brackets are not an operator by definition in C, and they do not concatenate strings. But they group statements and introduce new blocks. Maybe this is what the author meant. But however, it is at least inaccurate if not wrong.

Upvotes: 0

Steve
Steve

Reputation: 216273

Absolutely not. The curly braces in C as C++, C# and others delimit a block of code. It's an error on their site. There is neither the possibility of operator overloading since we talk of 'pure, old fashioned C programming language'

Upvotes: 2

Graham Borland
Graham Borland

Reputation: 60681

No, that's just nonsense. No idea what that's about.

Upvotes: 6

Related Questions