Thread: Test your C knowledge

  1. #16
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    >>What do you mean with out-dated? That is correct both syntatically and semantically though not usual style.

    I'm not saying it's incorrect. It's out-dated trick (because)that it's nothing unusual for most C programmers.
    Last edited by Bayint Naung; 07-15-2010 at 08:04 AM.

  2. #17
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Quote Originally Posted by Bayint Naung View Post
    I'm not saying it's incorrect. It's out-dated that it's nothing unusual for most C programmers.
    Ah, got it.

  3. #18
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by Bayint Naung View Post
    Code:
       3[array] = num;
    This is very out-dated...
    Every(almost all) C programmers know that after reading c-faq or IOCC code.
    It's not outdated, its legal C but you almost never see it except for exercise or maybe obfuscated C contests.

  4. #19
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    KIBO: If you would've read couple posts further you would've found out that that was already explained.

  5. #20
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Anyone who works professionally knows why this is important to understand. When you get a career in programming you'll find ancient code written like this perhaps for an older compiler. The world is filled with C code. In our case at work, we upgraded compilers and the old code was still there. What you do need to know are these little things so you can upgrade your code as needed to be current with the standard. For example, I'm sure you ran across "iostream.h" in C++ whereas the new standard header is iostream. Not to mention, upgrading from a C to C++ compiler means you need to change an old header "time.h" by removing the .h and adding a 'c' to the begnning of the file. Knowing these things help you become a top-notch C/C++ developer. So yes, you do need to understand it enough to read it and know the differences.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dxfoo
    Anyone who works professionally knows why this is important to understand. When you get a career in programming you'll find ancient code written like this perhaps for an older compiler. The world is filled with C code. In our case at work, we upgraded compilers and the old code was still there. What you do need to know are these little things so you can upgrade your code as needed to be current with the standard.
    That raises an interesting question though. Consider your original question: "What's wrong with this code while compiling on a C89 compiler?"

    I confess that my immediate reaction is to look for what might cause a compile error with respect to C89. But in truth, what is wrong is more than that. For example, the use of the identifier-list form for the parameter declarations of a function definition, although legal even in C99, is wrong, on the basis of readability and the fact that the arguments will not be converted to the declared parameter types. Likewise, the expression 3[array], although again perfectly legal even in C99, is also wrong, on the basis of readability. The use of implicit-int is perhaps more debatable, but again it could be regarded as wrong, on the basis that forward compatibility with C99 is easy to achieve, with increased readability by being explicit.

    Quote Originally Posted by dxfoo
    upgrading from a C to C++ compiler
    That is not actually an upgrade: they are different programming languages, despite what they have in common

    Quote Originally Posted by dxfoo
    means you need to change an old header "time.h" by removing the .h and adding a 'c' to the begnning of the file.
    And also change time to std::time, unless an appropriate using declaration or using directive is in scope.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Online Test Your Knowledge..
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 08-13-2009, 09:02 AM
  2. Easy to use random number test suite?
    By Sebastiani in forum General Discussions
    Replies: 3
    Last Post: 07-12-2009, 08:17 AM
  3. sustring test puzzle
    By WDT in forum C# Programming
    Replies: 3
    Last Post: 06-29-2009, 07:19 AM
  4. Why is my program freezing?
    By ShadowMetis in forum Windows Programming
    Replies: 8
    Last Post: 08-20-2004, 03:20 PM
  5. Question About Linker Errors In Dev-C++
    By ShadowMetis in forum C++ Programming
    Replies: 9
    Last Post: 08-18-2004, 08:42 PM