Is a C ++ program slower than a similar C program?

Suppose I wrote a C ++ program without using RTTI and polymorphism at runtime (no virtual function, no virtual inheritance), and classes do not have private / protected members, and special C ++ header files are not used (i.e. . use the C header files: cstring, cstdio... instead string, iostream...).

Then I want to write a similar program in C, to which the first type of function argument corresponds to the corresponding one struct.

For instance:

//C++ code

struct Custom
{
    int a;
    Custom() { }
    void change() { }
    ~Custom() { }
};

int main()
{
    Custom m; //init m
    m.change();
    //destroy m
}

/*C code*/

struct Custom
{
    int a;
};
void custom_init(Custom* like_this) { }
void custom_change(Custom* like_this) { }
void custom_destroy(Custom* like_this) { }

int main()
{
    Custom m;
    custom_init(&m);
    custom_change(&m);
    custom_destroy(&m);
}

++ , C- ()? , C ? , ++ RAII , ?

, , C ... ?

: ? , ++ - , , ( ? ? ?).

+5
3

++ RAII. CAN RAII ++.
++ C, .
C ++ - , , .

+6

, . ++ , C (, , ), .

, , , .

++, , C, . .

, ! , , . C , . - , . , , - .

+4

No, this is almost certainly not true. RAII alone will not make the program slower. Both C and C ++ compilers probably generate almost identical code for these examples.

+2
source

All Articles