![]() |
|
#1
|
|||
|
|||
Please Help, problems writing newbie c programPlease Help, What is wrong with this program ???
CPP / C++ / C Code:
Last edited by dsmith : 02-Mar-2004 at 19:41.
Reason: Added C-syntax highlighting
|
|
#2
|
||||
|
||||
|
Hello Soulfly. I am assuming that this program won't compile. It helps when you post if you can give us a hint of what is not working
![]() It appears that you are familiar with Pascal. In C, function calls are a bit different. First of all, you do not give the type of the parameters again. Also, C can only return a single value. If you want to return a parameter, you must pass it as an address and receive it as a pointer. For example, this function: CPP / C++ / C Code:
Should look more like: CPP / C++ / C Code:
This function would probably make more sense written as two functions, one that would return boolone and one that would return booltwo. For example: CPP / C++ / C Code:
Then to call it, use: CPP / C++ / C Code:
All of your functions need to be changed to be similar to this. HTH |
|
#3
|
||||
|
||||
|
Wow... okay, first of all, you need to separate your function parameters with commas. Second of all, once you declare a variable within a function header, it is local to that function and does not need to be declared again. You are declaring variables under your function headers, which will cause your program not to compile.
CPP / C++ / C Code:
|
|
#4
|
||||
|
||||
|
Quote:
Actually, in C++ you can simply receive the address and pass normally. CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
|
Quote:
CPP / C++ / C Code:
|
|
#6
|
||||
|
||||
|
Isn't that exactly what dsmith said? I was saying that you only need to use the reference operator in the function header, then anything you pass to it will be passed by address.
|
|
#7
|
||||
|
||||
|
My mistake
|
|
#8
|
||||
|
||||
|
Quote:
Okay, if there is one thing that I am, it is opinionated . And I just have to give my opinion on this. I am an old dinasour and I have never had a formal class in C++, but I do like it and I use some of its features and I am happy. But this is sick & wrong (IMHO), this does something totally different in C than in C++ apparently. I don't like this, because if you are familiar with C++ code and are reviewing/maintaining C code and try to do this you will get very different results than you expected. Once again, this is my opinion and I don't want to start a holy war. But if I was learning C++, I would avoid this type of function calling like the plague. I am open to hearing differing opinions, but keep the hits above the belt please. ![]() |
|
#9
|
||||
|
||||
|
I agree also. It hides the realities of the parameters. But in their defense, it does make the coding easier on the calling side. The compiler does all the thinking. I wonder if Billy had a lot of input
|
|
#10
|
||||
|
||||
|
I'm doing my Mouse-on-an-Island-with-Bridges-on-It program using the C method for portability. I haven't written anything large enough to cause problems while using the reference operator in function headers, so I'll probably just start using the C way instead.
|
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Chaintech Geforce 5600 FX problems | bartster74 | Computer Hardware Forum | 8 | 04-May-2004 13:16 |
| [Tutorial] Standard I/O | aaroncohn | C Programming Language | 20 | 27-Feb-2004 21:07 |
| compiling a program within another (C++) | Siphiro | C++ Forum | 5 | 06-Feb-2004 15:35 |
| error during program | rjd72285 | C++ Forum | 0 | 11-Nov-2003 18:49 |
| one program access another? | dgoulston | C++ Forum | 1 | 07-Oct-2003 11:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The