Thread: Connecting structs/lists

  1. #16
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by MutantJohn View Post
    Well, all valid C is valid C++.
    Here's some more code that is valid C99/C11 but invalid C++:

    Code:
    struct foo {
        int x;
    } y = { .x = 9 };
    It's a (sometimes) very useful syntax that unfortunately does not exist in C++. C took line comments and a handful of other little features from C++. Why can't C++ take this little C feature that has existed in C for 16 years now??

  2. #17
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by christop View Post
    Here's some more code that is valid C99/C11 but invalid C++:

    Code:
    struct foo {
        int x;
    } y = { .x = 9 };
    It's a (sometimes) very useful syntax that unfortunately does not exist in C++. C took line comments and a handful of other little features from C++. Why can't C++ take this little C feature that has existed in C for 16 years now??
    Oh wow, I didn't event know about that, thanks a bunch! (For those interested)

    It seems like in C++ it would be less useful though, just because of overloaded assignments and whatnot, still it would be sort of neat to be that specific. Another thing of note is that in C++11 there is a warning issued when an expression in an aggregate initialization is narrowing, which at least for myself means I use it less.

    I'm even more curious now if there's yet more stuff to discover on this topic lol.

    Edit:

    One thing I did think of was the auto keyword:

    Code:
    // C
    auto int a = 10;
    
    // > C++11
    auto a = 10;
    I didn't bring it up because it's a specifier without any real use, that I've never seen in actual code, so it seemed like a stretch...
    Last edited by Alpo; 08-13-2015 at 07:12 PM.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

  3. #18
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Well, all valid C is valid C++.
    O_o

    Sure.

    For funsies, you can make syntax highlighters cry if you get creative.

    Soma

    Code:
    #if defined(__cplusplus)
    #   include <cstdio>
    #else
    #   include <stdio.h>
    #endif
    
    #if defined(__cplusplus)
        using std::printf;
    #endif
    
    void ShowMessage()
    {
        int s = 0 //*!*/ 1; printf("You are probably using a C90 compiler.\n"); /*
        -1 + printf("You are probably using a C99, C11, or C++ compiler.\n");
        // */
        ;
    }
    
    int main()
    {
        ShowMessage();
        return(0);
    }
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  4. #19
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    Quote Originally Posted by phantomotap
    Code:
        int s = 0 //*!*/ 1; printf("You are probably using a C90 compiler.\n"); /*    -1 + printf("You are probably using a C99, C11, or C++ compiler.\n");
        // */
        ;
    (0.0)

    (-.-)

    (0.0)

    10 out of 10! (So 2/3 in binary :P). Edit: Derp, it would be 2 out of 2. I sometimes forget how to number correctly.


    Last edited by Alpo; 08-13-2015 at 08:19 PM.
    WndProc = (2[b] || !(2[b])) ? SufferNobly : TakeArms;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs and Linked Lists
    By ChickenChowMinh in forum C Programming
    Replies: 14
    Last Post: 10-03-2013, 01:50 AM
  2. with linked lists and structs
    By cable in forum C Programming
    Replies: 4
    Last Post: 10-10-2011, 08:11 PM
  3. Classes or Structs faster for Lists
    By White Rider in forum C++ Programming
    Replies: 24
    Last Post: 04-05-2002, 03:57 PM
  4. Replies: 3
    Last Post: 01-22-2002, 12:22 AM
  5. file i/o-structs,linked lists
    By new2c in forum C++ Programming
    Replies: 3
    Last Post: 12-16-2001, 11:31 PM