Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Why does -32768 have type signed long in the following platform?

Suppose that on a platform, the minimal signed value is −2^15 = −32768 and the maximum value is 2^15 −1 = 32767. The constant 32768 then doesn’t fit into signed and is thus signed long. As a consequence, the expression -32768 has type signed long. Thus the minimal value of the type signed on such a platform cannot be written as a literal constant.

From Modern C by Jens Gustedt.

It's trivial to understand why 32768 is signed long, but why is -32768 also signed long and not signed, given the minimum signed value of -32768?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Because -32768 is the positive literal 32768 (which does not fit into a 16-bit value and therefore must be represented by the next larger type), to which then the unary minus is applied (which does not change the type).

If you write e.g. ( ( - 32767 ) - 1 ), you get your constant in int type.

over 4 years ago · Santiago Trujillo Report

0

If int is a 16-bit type in your platform then 32768 doesn't fit in it. Therefore 32768 must have the next larger type which is long. -32768 isn't a negative integer literal but a unary minus applied to the literal 32768. Since 32768 is long, so is -32768

This is exactly the same as

  • -9'223'372'036'854'775'808LL is unsigned
  • Why does the smallest int, −2147483648, have type 'long'?
  • Why does MSVC pick a long long as the type for -2147483648?
over 4 years ago · Santiago Trujillo Report

0

-32768 is not actually an integer literal. It's the integer literal 32768 with the unary - operator applied to it.

Since on this system the value 32768 is outside the range of int, the constant 32768 has type long. Applying the unary - to a value of type long results in an expression of type long, therefore -32768 has type long.

A way to get the value -32768 with type int, the proper expression would be -32767 - 1. The integer constant 32767 has type int. Applying the unary - operator to it still gives us a value in the range of int, then subtracting 1 gives us an expression of type int with value -32768.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!