Showsize: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
(Created page with "a c program to tell you what the size of data types are: showsize.c <pre> #include <sys/types.h> #include <stdio.h> int main(void) { printf("In bits:\n"); printf("%d <-unsigned long\n", sizeof(unsigned long)*8); →‎mul8 to get it in bits: printf("%d <-unsigned long\n", sizeof(unsigned long)); →‎mul8 to get it in bits: printf("%d <-long long\n", sizeof(long long)*8); →‎mul8 to get it in bits: printf("%d <-int\n",...")
 
No edit summary
 
Line 20: Line 20:
</pre>
</pre>


Some errors need work on this.
compile is simple:
It used to work around the 2000s but now in 2023 not so much.
 
gcc showsize.c -out showsize
 
There are warnings.
 
sample out:
 
<pre>
In bits:
64 <-unsigned long
8 <-unsigned long
64 <-long long
32 <-int
32 <-unsigned int
32 <-unsigned int
</pre>


[[category:script]]
[[category:script]]

Latest revision as of 18:45, 26 February 2023

a c program to tell you what the size of data types are:

showsize.c

#include <sys/types.h>
#include <stdio.h>

int main(void)
{
        printf("In bits:\n");
        printf("%d <-unsigned long\n",  sizeof(unsigned long)*8); /* mul8 to get it in bits */
        printf("%d <-unsigned long\n",  sizeof(unsigned long)); /* mul8 to get it in bits */
        printf("%d <-long long\n",      sizeof(long long)*8); /* mul8 to get it in bits */
        printf("%d <-int\n",            sizeof(int)*8); /* mul8 to get it in bits */
        printf("%d <-unsigned int\n",   sizeof(unsigned int)*8); /* mul8 to get it in bits */
        printf("%d <-unsigned int\n",   sizeof(unsigned int)*8); /* mul8 to get it in bits */
        return 0;
}

compile is simple:

gcc showsize.c -out showsize

There are warnings.

sample out:

In bits:
64 <-unsigned long
8 <-unsigned long
64 <-long long
32 <-int
32 <-unsigned int
32 <-unsigned int