Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:32:32+00:00 2026-06-09T17:32:32+00:00

Code: typedef signed short SIGNED_SHORT; //16 bit typedef signed int SIGNED_INT; //32 bit SIGNED_SHORT

  • 0

Code:

typedef signed   short  SIGNED_SHORT;   //16 bit
typedef signed   int    SIGNED_INT;     //32 bit


SIGNED_SHORT x;

x = (SIGNED_SHORT)(SIGNED_INT) 45512; //or any value over 32,767

Here is what I know:

Signed 16 bits:
Signed: From −32,768 to 32,767
Unsigned: From 0 to 65,535

Don’t expect 45512 to fit into x as x is declared a 16 bit signed integer.

How and what does the double casting above do?

Thank You!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:32:34+00:00Added an answer on June 9, 2026 at 5:32 pm
    typedef signed   short  SIGNED_SHORT;   //16 bit
    typedef signed   int    SIGNED_INT;     //32 bit
    

    These typedefs are not particularly useful. A typedef does nothing more than provide a new name for an existing type. Type signed short already has a perfectly good name: “signed short“; calling it SIGNED_SHORT as well doesn’t buy you anything. (It would make sense if it abstracted away some information about the type, or if the type were likely to change — but using the name SIGNED_SHORT for a type other than signed short would be extremely confusing.)

    Note also that short and int are both guaranteed to be at least 16 bits wide, and int is at least as wide as short, but different sizes are possible. For example, a compiler could make both short and int 16 bits — or 64 bits for that matter. But I’ll assume the sizes for your compiler are as you state.

    In addition, signed short and short are names for the same type, as are signed int and int.

    SIGNED_SHORT x;
    
    x = (SIGNED_SHORT)(SIGNED_INT) 45512; //or any value over 32,767
    

    A cast specifies a conversion to a specified type. Two casts specify two such conversions. The value 45512 is converted to signed int, and then to signed short.

    The constant 45512 is already of type int (another name for signed int), so the innermost cast is fairly pointless. (Note that if int is only 16 bits, then 45512 will be of type long.)

    When you assign a value of one numeric type to an object of another numeric type, the value is implicitly converted to the object’s type, so the outermost cast is also redundant.

    So the above code snippet is exactly equivalent to:

    short x = 45512;
    

    Given the ranges of int and short on your system, the mathematical value 45512 cannot be represented in type short. The language rules state that the result of such a conversion is implementation-defined, which means that it’s up to each implementation to determine what the result is, and it must document that choice, but different implementations can do it differently. (Actually that’s not quite the whole story; the 1999 ISO C standard added permission for such a conversion to raise an implementation-defined signal. I don’t know of any compiler that does this.)

    The most common semantics for this kind of conversion is that the result gets the low-order bits of the source value. This will probably result in the value -20024 being assigned to x. But you shouldn’t depend on that if you want your program to be maximally portable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: typedef std::vector<int> cont_t; // Any container with RA-iterators typedef cont_t::const_iterator
Consider the following piece of code: 1 typedef std::deque<int> mydeque_t; 2 mydeque_t mydeque; 3
I am curious why this code works: typedef struct test_struct { int id; }
where is the mistake? My code here: typedef struct _box { char *dados; struct
The C code i need to convert into Java is: typedef struct { short
in this short code: class X { private: class Y { public: typedef void
I am so confused with this code in the book : typedef int (*healthCalcFunc)
Consider the following non-working code: typedef map<int, unsigned> mymap; mymap m; for( int i
I have the following C++ code: typedef int* IntPtr; const int* cip = new
All operations on standard signed integer types in C (short, int, long, etc) exhibit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.