Welcome, Guest. Please login or register.

Author Topic: My C homework  (Read 14355 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Jupp3

  • Sr. Member
  • ****
  • Join Date: Mar 2002
  • Posts: 364
    • Show all replies
    • http://jupp3.amigafin.org
Re: Mel's C homework
« on: February 26, 2007, 01:23:26 PM »
Quote
if (whitespace == 1)

If 0 and 1 (non-zero) are the only different values you need, you can always just do if(whitespace) (which in this case pretty much equals if(whitespace=1)) - on many (most?) CPU's it's faster and more compact to check whether or not a value is zero, rather than checking if it equals some other value. Basically this is also true for if(a==0), but probably many compilers can optimize that to if(!a)

As you probably have already noticed, this is often used as a way of error checking. Consider result=malloc(size); - if the allocation failed, you get NULL pointer. Personally whenever possible, I also use the same approach in my code. Another variant is to use zero as success, and non-zero as error code.

Also don't forget to avoid doing for(i=0; i
 

Offline Jupp3

  • Sr. Member
  • ****
  • Join Date: Mar 2002
  • Posts: 364
    • Show all replies
    • http://jupp3.amigafin.org
Re: Mel's C homework
« Reply #1 on: March 02, 2007, 11:35:07 AM »
Quote
I just wonder why you choose C, as that a language is old and on it's way out.

You know it's been going out since it was first published, still going (out) strong :-)

Also html is going out, and will be totally replaced with flash. Or is it still flash? At least it was >5 years ago...
Quote
I perfer object oriented stuff.

Me too. That's why I code C in object oriented way. imho, "being object oriented" is mostly the attitude of a programmer, more than a feature of a programming language.
Quote
yes, english is very old, and a huge part of the world still uses it. However it is evolving all the time, so learning old english first does not help you talk with people.

Luckily C is evolving aswell. There have been few newer standard revisions, but most notably there's steady development for various libraries, that you can use to do, well, just about anything.