![]() |
|
#31
|
||||
|
||||
|
Dave, your second solution pointed to one more solution for me -- and this is really lame. Of course the #define will work too:
CPP / C++ / C Code:
![]() __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
||||
|
#32
|
||||
|
||||
|
Okay Walt. For that you win the booby prize. That is pretty bad... but still meets the requirements.
![]() __________________
The best damn Sports Blog period. |
|
#33
|
|||
|
|||
|
Quote:
I kind of like it. The only problem is that printf() has already been prototyped in <stdio.h>. GNU gcc complains (with a warning) but executes OK. Borland bcc32 and Microsoft Visual C++ report it as an error and won't compile. In order for it to run on all standard c compilers, you should declare printf() with the same parameters as in <stdio.h> (as I did in my example). Of course, then you will be declaring that its type as int, and should return some value. The thing I like about puzzles like this (I'm not always good at puzzles): Once you get over the "it can't be done" frame of mind, many alternatives may come to you. My definition of Engineer is: "Problem Solver". Sometimes the hardest thing to overcome in solving a problem is your first impression that "it's impossible". Regards, Dave |
|
#34
|
|||
|
|||
|
Dang, everyone else's solution makes mine look really, really lame. I just nested the int main() function within the real main(). Technically, I didn't change the given main() function at all, the compiler (well, gcc at least, I don't know about the others) just ignores it.
Thus, the most pathetic solution of all: CPP / C++ / C Code:
|
|
#35
|
|||
|
|||
|
Quote:
This is a true aberration. main() is a very special function. You are only allowed to have one in standard C. Also, nested functions are not allowed in standard C. I am shocked that gcc lets you do this (it does--- I tested it). However, I kind of like the way that your mind works --- go for the bizarre! I think the rules should have included the requirements that the resulting program be totally compliant with C-language standards. However, inspired by your effort, I gladly give you credit for inspiring this one, that does obey the rules and is unquestionably a valid program for all standard C compilers. CPP / C++ / C Code:
I use the #if 0 construct all of the time to comment out blocks of code that may include /* */ comments. (In standard C, /* */ comments can't be nested.) Since the original program had no such comments, I could have just put "/*" before its first line and "*/" after its last line instead of using #if 0 Regards, Dave |
|
#36
|
|||
|
|||
|
Thank you for your insight, I can't believe I left out the possibility of using preprocessor macros, or comments for that matter...
|
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help with coding expectation maximization needed. thanks | edge | C Programming Language | 8 | 08-Nov-2005 06:00 |
| Some small things | Allowee | GIDSearch™ | 6 | 14-Jul-2004 02:40 |
| This is a small snippet from a much larger piece. | Tang_Quester | Open Discussion Forum | 1 | 19-Mar-2004 02:17 |
| Free 1st month / Free setup / No credit card needed...Plans start at 4.95 | LarryIsaac | Web Hosting Advertisements & Offers | 0 | 11-Oct-2003 15:03 |
| Script needed for letting user input a few days of data for tracking and analysis. | tradertt | MySQL / PHP Forum | 3 | 06-Mar-2003 03:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The