Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the compiler do here: int a = b * (c * d * + e)? [duplicate]

I had a strange bug in my program, and after a few hours of debugging, I found the following very stupid line:

int a = b * (c * d *  + e) 

If you don't see it: Between d and e I wrote * +, where just a +was intended.

Why does this compile and what does it actually mean?

like image 526
Michael Avatar asked May 20 '15 21:05

Michael


People also ask

How does a compiler work?

A compiler takes the program code (source code) and converts the source code to a machine language module (called an object file). Another specialized program, called a linker, combines this object file with other previously compiled object files (in particular run-time modules) to create an executable file.

How does the C++ compiler work?

Compilers are utility programs that take your code and transform it into executable machine code files. When you run a compiler on your code, first, the preprocessor reads the source code (the C++ file you just wrote). The preprocessor searches for any preprocessor directives (lines of code starting with a #).

Does C++ compile to C?

No. C++ -> C was used only in the earliest phases of C++'s development and evolution. Most C++ compilers today compile directly to assembler or machine code. Borland C++ compiles directly to machine code, for example.

What is compiling and linking in C++?

Compilation: the compiler takes the pre-processor's output and produces an object file from it. Linking: the linker takes the object files produced by the compiler and produces either a library or an executable file.


1 Answers

The + is interpreted as an unary plus operator. It simply returns the promoted value of its operand.

like image 82
Brian Bi Avatar answered Oct 02 '22 00:10

Brian Bi