![]() |
|
#1
|
||||
|
||||
Today's C/C++ Programming Tip :-)Friends,
Hope this thread will be very useful for all of us! Here is a start: Language: C For people using the GNU Compiler: Linux: GNU gcc compiler Windows: Dev C++, Code::Blocks, MingW compiler Ever think this is a C program? buggy.c CPP / C++ / C Code:
The compiler is so happy about it! In Windows too, the program compiles fine, and the user thinks that the program is correct! But Alas! The program is not a valid ANSI C program. C is a procedure oriented language, and one has to declare the variables at the start. You cannot declare them in the middle. Comment style: There are NO // comment in ANSI C standard. And you cant use variable types for array initialization!. So, we have to configure the compiler to identify and correct the errors in the program. For that, there are three compiler flags: -ansi This flag tells the compiler to enforce ANSI C standards -pedantic More pedantic ansi, warnings for stuff you probably didn't mean. -Wall Show all reasonable warnings (there are more). So, you should make sure that it is running as a standard C compiler and not a GNU C compiler. * gcc -ansi -pedantic makes it run as a standard C compiler * gcc -ansi -pedantic -Wall makes it run as a standard C compiler and check for several types of errors If you use an IDE such as Dev C++, then you can go to Tools->Compiler Options and add the commands when calling the compiler. (See the attachment.) Now, the following warnings and error messages appear: Quote:
Now, correct the errors and make the ANSI compiler happy. Cheers, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#2
|
||||
|
||||
|
Quote:
I guess ur using an old compiler urself Last edited by cable_guy_67 : 27-Mar-2006 at 10:16.
Reason: Similar comments blocked by moderated forum
|
|
#3
|
||||
|
||||
Re: Today's C/C++ Programming Tip :-)Language: C/C++
Level: Beginner Dont use 0 before numbers. Instead of using 010, use 10. For example consider this example: CPP / C++ / C Code:
Expected output: Code:
Actual Output: Code:
So, we should be careful in using numbers. Another example: CPP / C++ / C Code:
As expected, the output was: Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#4
|
|||
|
|||
Re: Today's C/C++ Programming Tip :-)Thanx for the tip Paramesh, I didn't know that...., maybe I thought that compuetrs these days have that much of IQ to handle numbers beginning with a zero.
Jokes apart, suppose at runtime a user enters a number beginning with a zero would the compiler take it as a hex/oct number? Then how can I "decode" them are there any standard library features to use or do i need to develop my own code (P.s. I use Turbo C++ 3.0) |
|
#5
|
|||
|
|||
Re: Today's C/C++ Programming Tip :-)if you need to use before numbers, use a double. right?
|
|
#6
|
|||
|
|||
Re: Today's C/C++ Programming Tip :-)if you need to use 0 before numbers, use double instead of int.
|
|
#7
|
|||
|
|||
Re: Today's C/C++ Programming Tip :-)Quote:
Paramesh, You English borders on to flawless. How come? You command over the basics is so refreshing. Keep up the good work. |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read/ Write EXCEL files using C/C++ programming | confused_pig | C++ Forum | 4 | 25-Nov-2005 01:27 |
| [Tutorial] GUI programming with FLTK | dsmith | FLTK Forum | 10 | 03-Oct-2005 16:41 |
| Network programming | pointer | C++ Forum | 2 | 20-May-2005 15:36 |
| GUI programming | crystalattice | C++ Forum | 5 | 14-Sep-2004 13:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The