Thread: Help needed for c programming only

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    Elysia, you use const* for string literals, because on your system, they ARE sting literals. As you know, on my compiler, they are NOT.
    So naturally, I don't use const* for those string literals. I only do that on compilers where they ARE constant.

    You can call it a "bad practice" until the cows come home - but I'm WAY too pragmatic to call something something it is not, or change something that works perfectly.
    Don't give me that. You are using an old outdated compiler. So there is a huge chance that what works for you, should not work or will not work on today's modern and standards compliant compilers.
    Just because it works for you, doesn't mean it will work for others nor that others should do as you.
    Do you remember what this board is about? Standard compliance, for one thing.
    You do what you want with your own code, but when you show your code to others, you had better make sure you don't use as many bad practices. Remember that they are usually newbies--they don't know any better! What we teach them is what they learn. Therefore we must use good judgment to create good programmers out there, not to spawn more people that relies on undefined behavior, like you.

    atoi() worked perfectly. I can't say "don't use atoi() because it might fail", when it's working perfectly. Any C function can fail if it's not used correctly.
    I did not say don't use. I said that strtol is better.
    And I would also ask if there is a point in using something that is inferior if there is a better alternative that always works. Do you use gets instead of fgets? I thought not.
    The point is: strtol is superior to atoi and hence it is better to learn to use it properly instead of atoi. Right? Right???
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Elysia View Post
    Don't give me that. You are using an old outdated compiler. So there is a huge chance that what works for you, should not work or will not work on today's modern and standards compliant compilers.
    Just because it works for you, doesn't mean it will work for others nor that others should do as you.
    Do you remember what this board is about? Standard compliance, for one thing.
    You do what you want with your own code, but when you show your code to others, you had better make sure you don't use as many bad practices. Remember that they are usually newbies--they don't know any better! What we teach them is what they learn. Therefore we must use good judgment to create good programmers out there, not to spawn more people that relies on undefined behavior, like you.


    I did not say don't use. I said that strtol is better.
    And I would also ask if there is a point in using something that is inferior if there is a better alternative that always works. Do you use gets instead of fgets? I thought not.
    The point is: strtol is superior to atoi and hence it is better to learn to use it properly instead of atoi. Right? Right???
    There are a lot of degrees of standard compliance. None of my three compilers are fully compliant with the latest standards. Most students' compilers are not fully compliant with that, either. Some of them even have Turbo C!

    I expect the reader to either know how to use his own compiler, or ask, and I will try to assist him or her. You can't learn about programming, and not know how to work with your compiler.

    Have you forgotten that there are millions of lines of code out there that they will run into, that is NOT standard compliant? Our space shuttle software is not "standard compliant". When may we expect to see you on the news demanding NASA have it changed?

    Do you not see the hypocrisy of what you're doing? Business software is not up to the latest C standards, scientific software is not up to the latest C standards. I'll bet you can hardly find anywhere on earth, where the software is 100% up to the latest C standards, if they use C for 50% of their software.

    But here you are complaining on and on about my tiny teeny contribution to programming. What is this, about the 4th time, you've pulled this act out of the suitcase now?

    Give it a rest, or get me banned. I'm tired of your nonsense on this matter.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, you fail to understand.
    This is not about using the latest and best compiler which is 100% standard compliant. This is about not depending on undefined behavior.
    Can you declare string literals as const char* on Turbo C without it breaking? The answer is yes. Can you do it on modern compilers? The answer is yes. So do you have anything to lose? The answer is no.

    The point is to teach everyone to be as standard compliant as possible. Sure you may see or work with non-standards compliant code, but that is not the point. The point is that the students here should know about standard compliant ways and use them whenever possible. You are not helping in this matter.

    Let's take an example.
    You declare your string literals as char* and unknowingly modify them! On Turbo C, your school compiler, it all works fine and dandy.
    But later you come home and you use a modern compiler that people have suggested you use. Then when you suddenly run the code, all goes to the pits! The code crashes spectacularly. And why? Because you have used non-standard compliant code! Or perhaps even better - undefined behavior. Had you not been such a pighead and avoided undefined behavior and used standard compliant code, it would have worked on both compilers.

    To further my point, you should not rely on what works on one compiler, because who says it will work in all compilers that you will work with in the future?
    Is it so difficult to use const char* instead of char*? Or do you want to become another esbo?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Dec 2009
    Posts
    30
    Sorry for not mention the compiler that I use before post the code. My compiler is C free standard. So is my fault that didn't mention my compiler.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by zhengkoon8
    My compiler is C free standard.
    A quick check shows that C-Free is an IDE, not a compiler. It supports a number of different compilers, so you should find out exactly which compiler is in use.
    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

  6. #21
    Registered User
    Join Date
    Dec 2009
    Posts
    30
    I thought c free standard is a compiler. Because this is the software that i use to write the code and test it

  7. #22
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Probably is MinGW or Borland...maybe the free Watcom (back in the day this compiler rocked) but they all look like Windoze/DOS compiles from the home page....CFree is a front-end. Looks like something that they made out of Delphi some years ago....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C is a programming language, and therefore, there exists a C Language Standard. This states what the language is, what is it capable of, how it should work, etc.
    Then there are a number of compilers that implements the standard. Some are better than others. Some are older, some are newer.
    But the thing is - if we follow the standard, we are guaranteed to be able to compile our software in every working compiler. Or at least that's the theory behind it. Some compilers are not entirely standards compliant and can allow code that does not follow the rules of the standard and barfs at code that actually follows the standard.
    But regardless, we should follow the standard as closely as we can.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DIfference between , and ;
    By rocketman03 in forum C++ Programming
    Replies: 6
    Last Post: 10-21-2009, 09:46 AM
  2. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  3. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM

Tags for this Thread