Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which C Features are influenced by/derived from C++ Features? [closed]

What are features from the actual C Standard, which originally weren´t part of C, but were invented in/for C++ and because of its benefits, were later adopted to C?

One prominent example is the single-line comment //, which originally came from C++ and later was adopted by C.

Do you know more features of the actual C Standard, which explicitly or implicitly came from the development of C++?

Info: Of course, I know that C++ is derived from C but i was just thinking about which features was adopted from the development of its derivative, C++.

like image 284
RobertS supports Monica Cellio Avatar asked Dec 18 '19 16:12

RobertS supports Monica Cellio


Video Answer


2 Answers

I cannot confirm that they were definitely influenced by C++ directly1, but here is a list of features in standard C++ that were added in C99:

  • single line comments (as mentioned)
  • inline functions
  • variables allowed after beginning of block
  • boolean datatype
  • complex math library

C11:

  • Anonymous unions (C11 allows anonymous structs too). Anonymous unions were already in standard C++. (Anonymous structs are still not allowed in standard C++).

1 For example BCPL, predecessor of B which in turn is the predecessor of C already had same syntax for single line comments. Some of these may have been supported as language extensions in some C implementation prior to their incorporation to standard C++. In these cases both standard C and standard C++ may have been influenced by the same source, rather than influencing one another.

like image 143
eerorika Avatar answered Oct 17 '22 07:10

eerorika


Attributes were added in C++11 and will be added in the next C standard revision C2x. The proposal (and here) for this feature specifically references C++.

Attributes can be useful for providing information that, for example, helps the compiler to issue better diagnostics or optimize the generated code. Source

Example:

int [[attr1]] i [[attr2, attr3]];

[[attr4(arg1, arg2)]] if (cond)

{
    [[vendor::attr5]] return i;
}

In this example, "attribute attr1 applies to the type of variable i, attr2 and attr3 apply to the variable itself, attr4 applies to the if statement and vendor::attr5 applies to the return statement." Source

like image 43
Adam Avatar answered Oct 17 '22 08:10

Adam