Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/sbin/mksh
- set -x
- #rm -i a.out
- gcc ${@} -x c - <<'EOF' && ./a.out
- #include <stdio.h>
- #include <stdint.h>
- #include <limits.h>
- #include <sys/types.h>
- #define psizeof(tn) (printf("Size of " #tn " is %d\n",(sizeof (tn))))
- int f1(char * cp)
- {
- return 1;
- }
- double f2(int x, int y, double dx, int * ip)
- {
- return 0.0;
- }
- int main ( int argc, char * argv[] )
- {
- printf("Size of CHAR_BIT is %d\n",CHAR_BIT);
- psizeof(int);
- psizeof(short);
- psizeof(char);
- psizeof(unsigned char);
- psizeof(long);
- psizeof(long long);
- psizeof(double);
- psizeof(float);
- psizeof(long double);
- psizeof(intmax_t);
- psizeof(int *);
- psizeof(long *);
- psizeof(float *);
- psizeof(double *);
- psizeof(&f1);
- psizeof(&f2);
- psizeof(off_t);
- psizeof(quad_t);
- psizeof(size_t);
- return 0;
- }
- EOF
- #now shifttype.c */
- gcc ${@} -x c - <<'EOF' && ./a.out
- #include <stdio.h>
- int main(int argc, char * argv[])
- {
- signed int i=-1;
- signed int j;
- puts("*************************");
- printf("i=%d\n",i);
- j= i>>1 ; /* right shift */
- printf("after right shift 1=%d, %X hex\n",j,j);
- if ( -1 == j ) { /* unspesified in C */
- /* arithmetic shift, sign bit kept */
- puts("right shift, >> , is arithmetic, keeps sign bit");
- } else {
- puts("right shift, >> , is logical");
- }
- puts("*************************");
- unsigned int x=0; /* strangely, this works */
- unsigned int y; /* c99 feature? gcc feature?,
- * I don't need -x c, for this to work, when gcc==
- * gcc version 4.0.1 (Apple Computer, Inc. build 5370)
- */
- printf("x=%d\n",x);
- y=x<<1;
- printf("after left shift, <<, y=x<<1, %d, %X hex\n",y,y);
- puts("*************************");
- x=1;
- printf("x=%d\n",x);
- y=x<<3;
- printf("after left shift, << ,y=x<<3, %d, %X hex\n",y,y);
- puts("*************************");
- }
- /*
- Checking spelling of ARITHMETIC...
- ARITHMETIC is correct
- * kinda rhymes with Arabic
- * Why do I feel arithmetic shift, when not part of a, ones-complement
- * dinosaur, was only there should the programmer should'nt use it?
- * Was it essential to provide, no way, to determine ones-complement?
- * with a C program? Since Architecture is Compiler + machine,
- * was C a scientific success, when, some company, did that?
- * No, not that, what I was thinking, naturally, essentially,
- * make the dinosaur live again, with the compiler...
- */
- EOF
- #rm -i a.out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement