Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have a triple minus signs in C programming? What does it mean? [duplicate]

Tags:

c++

c

Possible Duplicate:
Why doesn’t a+++++b work in C?

I got this from page 113 on the "An Embedded Software Primer" by David Simon.

I saw this statement below:

iHoursTemp = iHoursTemp + iZoneNew ---iZoneOld; 

Can you really have three minus signs in this line? What does a triple minus sign mean?

I believe it is a C programming statement.

like image 468
Joseph Lee Avatar asked Dec 14 '12 07:12

Joseph Lee


People also ask

WHAT IS &N in C?

*&n is equivalent to n . Thus the value of n is printed out. The value of n is the address of the variable p that is a pointer to int .

Why do we use double and at in C?

In programming, a double ampersand is used to represent the Boolean AND operator such as in the C statement, if (x >= 100 && x >= 199).


2 Answers

It is equivalent to:

iHoursTemp = iHoursTemp + (iZoneNew--) - iZoneOld; 

This is in accordance with the maximal-munch principle

like image 70
Robᵩ Avatar answered Sep 18 '22 06:09

Robᵩ


The correct answer is (as Rob said) the following:

iHoursTemp = iHoursTemp + (iZoneNew--) - iZoneOld; 

The reason it is that way and not

iHoursTemp = iHoursTemp + iZoneNew - (--iZoneOld); 

is a convention known as maximum munch strategy, which says that if there is more than one possibility for the next token, use (bite) the one that has the most characters. The possibilities in this case are - and --, -- is obviously longer.

like image 27
imreal Avatar answered Sep 20 '22 06:09

imreal