Thread: short char and long char

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    90

    short char and long char

    Hi

    int variable take four byte, short int take two byte and long int take eight bytes

    the same char takes one byte so long char should be take 2 bytes

    so I wrote program to get result

    Code:
    #include <stdio.h>
    
    int main()
    {
        char x;
      //  short char y;
         long char z;
        
        printf("size of int = %d \n", sizeof(x));
       // printf("size of short int = %d \n", sizeof(y));
        printf("size of long int = %d \n", sizeof(z));
        return 0;
    }
    error: both ‘long’ and ‘char’ in declaration specifiers long char z;
    ^~~

    Does this mean that short / long cannot be used with char?
    Last edited by Player777; 04-13-2020 at 12:01 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Does this mean that short / long cannot be used with char?
    Yes.

    There's a wchar_t if you want wider characters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    90
    Quote Originally Posted by Salem View Post
    > Does this mean that short / long cannot be used with char?
    Yes..
    Thanks okay but I don't understand the reason behind this why we can't use short /long with char ?

    as I know if we want to modify the size of variable we can use modifier short, long

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Thanks okay but I don't understand the reason behind this why we can't use short /long with char ?
    Because not every permutation of every qualifier with every type makes sense.

    Also, K&R and the subsequent ISO standards have either never considered it, or considered it important enough that being able to say 'long char' was a useful enough idea to be incorporated into the language.

    > as I know if we want to modify the size of variable we can use modifier short, long
    But that's only fully defined for 'int'.

    You can have 'long double', but there is no 'short double' or 'unsigned double'.

    You can have 'signed char' and 'unsigned char', but there are no length qualifiers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do I convert a long long int into a char array?
    By Once-ler in forum C Programming
    Replies: 15
    Last Post: 02-22-2013, 01:46 PM
  2. How to convert char array of 64 bytes to long long int
    By pkumarn in forum C Programming
    Replies: 19
    Last Post: 03-06-2012, 02:23 AM
  3. Casting short to char*
    By Hawkin in forum C Programming
    Replies: 14
    Last Post: 02-03-2011, 01:09 PM
  4. short value to char
    By downfall80 in forum C Programming
    Replies: 4
    Last Post: 06-03-2009, 03:50 AM
  5. Replies: 8
    Last Post: 05-13-2003, 02:47 PM

Tags for this Thread