Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,950 questions

51,892 answers

573 users

How to check whether a type is signed or unsigned in C

1 Answer

0 votes
#include <stdio.h>

#define is_type_signed(t) (((t) - 1) < 0)
#define is_signed(t) printf( #t " is %s\n", is_type_signed(t) ? "signed" : "unsigned" );

int main(void)
{
    is_signed(int);
    is_signed(unsigned int);
    printf("%d\n", is_type_signed(int));
    printf("%d\n", is_type_signed(unsigned int));
    
    is_signed(char);
    is_signed(unsigned char);
    printf("%d\n", is_type_signed(char));
    printf("%d\n", is_type_signed(unsigned char));

    is_signed(long);
    is_signed(unsigned long);
    printf("%d\n", is_type_signed(long));
    printf("%d\n", is_type_signed(unsigned long));

    return 0;
}




/*
run:

int is signed
unsigned int is unsigned
1
0
char is signed
unsigned char is unsigned
1
0
long is signed
unsigned long is unsigned
1
0

*/

 



answered Jul 11, 2023 by avibootz

Related questions

1 answer 90 views
1 answer 103 views
2 answers 164 views
1 answer 113 views
1 answer 131 views
1 answer 65 views
2 answers 126 views
...