I have some code which looks like the following:
How do I port to c++?Code:void x(int a) {
do something with a
}
void y(int b) {
return x(50);
}
Regards
/RP
Printable View
I have some code which looks like the following:
How do I port to c++?Code:void x(int a) {
do something with a
}
void y(int b) {
return x(50);
}
Regards
/RP
Wait, I'm not allowed to use void functions in C++? Oh no my life, ruined!
ROFL :D:D:pQuote:
Originally Posted by Tonto
Funny guy ey.....I urgently need help on this.
So don't laugh about silly stuff, give some help instead.
And if your'e so geeky that you can't find anything else to laugh about get a life.
I'm just curious if this is the same thing as doing:
Regards,Code:
void x(int a) {
do some stuff....
}
void y(int b) {
x(50);
}
/RP
In regards to your original question:
Let's see, I build the project and woops!Code://///////
// Test suite
//////////
void x(int a)
{
a += 50;
}
void y(int b)
{
return x(50);
}
int main(int argc, char* argv[])
{
y(10);
}
Yeah, you can't return a value, it's a void function specifying it won't return a value. However, from your updated post:Quote:
Originally Posted by VC6.0++
Works fine. No errors there. Here's a short thing about functional programming and void: http://www.mtsu.edu/~csci117/manual/lab8/lab8.html and another small reference: http://www.fredosaurus.com/notes-cpp...uncstruct.html and all of this is perfectly acceptable in both C and C++. We're just elitist ..........es around here, sorry. A quick google search on void functions does solve our issue quite nicely however!Code://///////
// Test suite
//////////
void x(int a)
{
a += 50;
}
void y(int b)
{
x(50);
}
int main(int argc, char* argv[])
{
y(10);
return 0;
}
yes but this is why I ask....it's a c snippet which I would like to port to c++
could I just replace the return x(50) with x(50) and that will do the same?
Mate I'm a self confessed geek. Read the sig.Quote:
Originally Posted by seizmic
are you like not very bright or?
>> could I just replace the return x(50) with x(50) and that will do the same?
The same? No of course not. Then you are not returning a value anymore. But seeing as you can't do that kind of stuff in 'void' functions in the first place, it doesn't matter. So you could say yes it is the same, but I mean, all it seems you want to do is call the function, you can not return a value. That's just how void functions work, and why they exist. Also try reading the articles I provided in my above post. I picked them out because I felt they would answer many of the questions you might have, including the one you just asked. You also might like reading this more general howstuffworks article on C functions:
http://computer.howstuffworks.com/c12.htm
It does a good job at bringing the this important concept of programming down to basic terms, including 'void' functions.
Oh god not again... started an 'argument' with someone possessing the mental intelligence of a 12 year old :rolleyes:
I'm going to be a good boy this time mods :D
seems like ahluka has to much time on his hands.....why not do something constructive with it...like go dr_wn himself or something like that
:o Amateur remarks
The thought of low level programming excites me. <- hmmm I wonder if you even know what low level is
I was wondering if you'd start questioning my programming abilities. Seeing as programming has been my sole hobby for the past 5 years...
Low level programming would be a reasonable description for any compiled (not interpreted - well not any I know of) language other than VB, C#, J# or Java (Java IMO BTW).
C/C++ are reasonably low level languages, but my favourite LLL of all time iiiiiiiiiis... Assembly! I do prefer Intel syntax but obviously there are times when you just need to write in AT&T syntax (GCC inline asm for example). Well not that syntax makes any difference anyway. Not the most practical LLL in the world, but short of programming in 'raw' machine code...
Don't you agree?
*edit*
Oh yes and I'm currently programming in assembly for my electronics coursework. Working with binary literals all the time is a pain though. ;)
I guess that would be in the eye of the beholder or in this case the programmer.....so therefore I think your'e wrong.
From a c,c++,java programmers view -> assembly is LLL
From an assembly programmers view -> c,c++,java are typically HLL.
From an machine code programmer (if any such exist nowadays) -> assembly is HLL
This gives a contradiction in terms what machinecode and assembly programmers think they are dealing with.
I'm currently also involved in assembly programming of the ARM processor.
Mainly working with srecords.