Thread: What are some obscure C statements?

  1. #1
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266

    What are some obscure C statements?

    Has anyone got any extremely obscure yet very useful C statements?

    This one isn't so obscure but I have not seen it in any text book I've read:

    Code:
    int x = 2;
    
    printf("%i\n",!!x) // x != 0
    This one I had never seen either:

    Code:
    int array[5];
    int (*ptr_to_array)[5] = &array
    
    (*ptr_to_array)[0] = 5;
    
    printf("%i\n",(*ptr_to_arry)[0]);
    Is the second one ever even useful?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Not in my opinion! PITA!

    The obscure C stuff for me, is the low level io - using file handles instead of file streams, etc. How useful I'm not sure.

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    x = (x > 10) ? x : 10;

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by CommonTater View Post
    x = (x > 10) ? x : 10;
    Oh Yeah! Good one!!

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Bayint Naung View Post
    Unrelated, but nonetheless relevant:

    OIOIC

    Read the code and you'll understand.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by Sebastiani View Post
    OIOIC
    You know, everytime I see his/her name I can't help but read it as Perverse Zhao. I'm still not sure if that's a subconscious comment on the project or my uncouth mind.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    Oh Yeah! Good one!!

    Yeah... and the really sad thing is I use it quite often.

    Such as ....

    x = ((x % 30) > 14) ? x + 15 : x - 15;

    Which I actually used not too long ago...

  9. #9
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Talking this one is cute

    Code:
    #include "stdio.h"
    #define e 3
    #define g (e/e)
    #define h ((g+e)/2)
    #define f (e-g-h)
    #define j (e*e-g)
    #define k (j-h)
    #define l(x) tab2[x]/h
    #define m(n,a) ((n&(a))==(a))
    
    long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
    int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
    
    main(m1,s) char *s; {
        int a,b,c,d,o[k],n=(int)s;
        if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
        else switch(m1-=h){
            case f:
                a=(b=(c=(d=g)<<g)<<g)<<g;
                return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
            case h:
                for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
            case g:
                if(n<h)return(g);
                if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
                else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
                if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
                return(o[b-g]%n+k-h);
            default:
                if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
                for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
            }
    }
    I'm using MS VS 2010, ignore any warnings... it worked fine. The only thing useful was, it gave me a laugh after running it.

  10. #10
    Registered User
    Join Date
    Jul 2010
    Posts
    27
    Quote Originally Posted by Char*Pntr View Post
    Code:
    #include "stdio.h"
    #define e 3
    #define g (e/e)
    #define h ((g+e)/2)
    #define f (e-g-h)
    #define j (e*e-g)
    #define k (j-h)
    #define l(x) tab2[x]/h
    #define m(n,a) ((n&(a))==(a))
    
    long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
    int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
    
    main(m1,s) char *s; {
        int a,b,c,d,o[k],n=(int)s;
        if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
        else switch(m1-=h){
            case f:
                a=(b=(c=(d=g)<<g)<<g)<<g;
                return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
            case h:
                for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
            case g:
                if(n<h)return(g);
                if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
                else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
                if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
                return(o[b-g]%n+k-h);
            default:
                if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
                for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
            }
    }
    I'm using MS VS 2010, ignore any warnings... it worked fine. The only thing useful was, it gave me a laugh after running it.
    Really cool!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Skipping If Statements?
    By CBecker5000 in forum C Programming
    Replies: 1
    Last Post: 11-08-2009, 04:05 PM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Replies: 3
    Last Post: 12-06-2008, 07:54 PM
  4. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  5. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM