Old 04-10-2008, 02:51 AM   #1
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default Why is MAIN of type INT ?

Seriously OT I know, but...

Why is this?
__________________
REAPER? Oh yes...
Deric is offline   Reply With Quote
Old 04-10-2008, 03:13 AM   #2
404NotFound
Human being with feelings
 
404NotFound's Avatar
 
Join Date: Oct 2007
Location: Berlin, GER
Posts: 199
Default

the number the main() function returns is your program's error code. It lets other applications/the shell know if your program was executed successfully.
404NotFound is offline   Reply With Quote
Old 04-10-2008, 03:23 AM   #3
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default

404NotFound,

Thanks for the quick response

Many thanks for answering this - I'm getting my head around the how/what/why of C++ (since the end of last week) and this is very useful.

Edit : I'd like to know just this now:

How can another program query what the output (of the initial main() ) is?

Edit: Following questions answered after more reading (apologies if anyone's started typing a response!)

Does that mean that return 0; gives main() a value of zero?
Edit: Yes - if the Return is within the main() routine.

If this is the case, does void exit (int n); supply main() with n?
Edit: Yes.

Answers to any of the above much appreciated!

Cheers
__________________
REAPER? Oh yes...

Last edited by Deric; 04-10-2008 at 05:13 AM. Reason: Answered 2of3 questions.
Deric is offline   Reply With Quote
Old 04-10-2008, 05:37 AM   #4
404NotFound
Human being with feelings
 
404NotFound's Avatar
 
Join Date: Oct 2007
Location: Berlin, GER
Posts: 199
Default

I just spent over an hour looking for an answer... it looks like it's rather difficult to query exit codes from within a program. I haven't found any simple solution yet.

Exit codes are usually used by shell scripts (like Windows .bat or .cmd files and Unix .sh scripts). They can use them for simple case switching, you can also pass the code to another program as an argument.
404NotFound is offline   Reply With Quote
Old 04-10-2008, 07:39 AM   #5
sws
Code Monkey
 
sws's Avatar
 
Join Date: Sep 2007
Location: Madison, WI
Posts: 850
Default

If you execute a subprogram from within your code using _spawnl() or its derivates it will return the exit code of the subprogram. The way I understand it, the only process that can see the exit code is the parent process (often explorer.exe in Windows or your shell in unix).
sws is offline   Reply With Quote
Old 04-10-2008, 09:38 AM   #6
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default

Thanks to both of you.

404NotFound - that is extremely kind of you, I hope my progress (in this area) will be of use to you too soon, thank you.

OK, so far we agree (I think) that we can return a code to a function but we don't know how to determine that functions returned code from another program.

There should be a way to define this (return code) as some sort of 'program variable' (sorry - my terminology is currently lacking) such that, should another program run the program, it can determine it's return code (if that code !=0).

Thanks for all the generous help so far! (I love this place)
__________________
REAPER? Oh yes...
Deric is offline   Reply With Quote
Old 04-10-2008, 09:43 AM   #7
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,649
Default

Well, in Windows there is a way to CreateProcess() or some such which will return the return code of the created process (program) in some way or another.

Is this purely of academic interest or do you think this has some application in connection with Reaper Extension plugins? (There is no latter application, as far as I can tell. Except if you launch another program from a Reaper Extension plugin and need to know the exit code of that other program.)
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 04-10-2008, 10:05 AM   #8
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default

Hi Xenakios,

Well... I'm learning C++ as a direct result of Cockos opening up elements of REAPER. As you know I started this 'game' on Friday (with your and SWS' help) and am trying to understand how things can communicate.

As far as this specific question goes - I wanted to be able to drive a program's decision based upon the result of a second program.

I want to keep things as compact, and as modular, as possible.

I was also hoping to be able to implement this idea with testing stuff.

I think I've got another couple of days of solid learning until I feel I have a grip on the basics of the commands. This will enable me to be able to 'read' code much faster than at present.

As you know, we learn a lot by reading how others have implemented a solution to a given problem.

Specifically, at this stage, I am looking at trying to do a ground-up write of the 01X (surface) program as I'll learn a lot doing this - which will be useful for implementing other stuff, i.e. integrating other kit easily and quickly.

Ultimately I want to be able to drive REAPER from surfaces (for the most part) with 'intelligent' surface switching and mapping for VST/VSTis etc.

Basically - I want to get to a place where everything is 'focus' driven, with the additional benefit of being able to 'see' (on the REAPER GUI) how everything is mapped onto whatever surface(s) one is using...

So I guess I'll be asking about GUI-semi-transparency in a few weeks... (you'd best get reading mate )

__________________
REAPER? Oh yes...
Deric is offline   Reply With Quote
Old 04-10-2008, 11:21 AM   #9
sws
Code Monkey
 
sws's Avatar
 
Join Date: Sep 2007
Location: Madison, WI
Posts: 850
Default

Quote:
Originally Posted by Deric View Post
There should be a way to define this (return code) as some sort of 'program variable' (sorry - my terminology is currently lacking) such that, should another program run the program, it can determine it's return code (if that code !=0).
To be clearer, do this:
Code:
int iRet = _spawnl(_P_WAIT, "c:\somepath\someprog.exe");
Your program runs, and when it exits, the value returned from main() or the value passed to exit() will be in the variable iRet.

Last edited by sws; 04-10-2008 at 11:24 AM.
sws is offline   Reply With Quote
Old 04-10-2008, 11:29 AM   #10
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default

Ayyy.... SWS...

OK! That's great! I'll be testing that this weekend (bit more reading and learning to do first!).

Thanks! Thanks a lot!

Now I just have to make sure something cool comes from all this!

Cheers SWS!



Nice one!
__________________
REAPER? Oh yes...
Deric is offline   Reply With Quote
Old 04-10-2008, 11:47 AM   #11
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,649
Default

You probably should tell something about what you are trying to do, especially if it is related to Reaper Extension plugins. We might be able to give you some advice and maybe prevent you from doing some extra unnecessary work and research.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 04-10-2008, 11:47 AM   #12
sws
Code Monkey
 
sws's Avatar
 
Join Date: Sep 2007
Location: Madison, WI
Posts: 850
Default

No problem Deric, good luck!
sws is offline   Reply With Quote
Old 04-10-2008, 12:26 PM   #13
Deric
Human being with feelings
 
Join Date: Mar 2007
Posts: 794
Default

SWS, thanks for the kind words!

Xenakios, I sort of explained one of the places I want to go in my post (above/below - depending on how you've got your view options set). Please be patient at the moment I am getting up to speed with C++ so that I will have some idea of what the hell I'm talking about as well as some understanding of what will/won't be feasible.

If you can give me until next week I should have a good enough idea of what's going on to be able to get re-written surface code out for the 01X. As explained in an earlier post I am using this as a test-bed to help me learn a bit.

Basically I just need to get on with learning about the language-of-choice here (C++) before I do anything else. Then I'll be in a position to have a reasonable-enough conversation with most others who know this language, or other languages.

I've a few things in mind but there's no rush. I'll need any and all the help I can get when the time comes I can assure you! I don't really see it as all the help 'I' can get - I'd rather view it as a team effort - and if we can get a few of us that are willing to do the homework we might just make something pretty seriously cool... maybe

So, if I may, I will get on with learning the principles of the coding language (as I have been for a few days now) and will then be in a more-informed position to communicate on a more-sensible level!

My hope is that, if we can get support, we agree on task-sharing and using our relative strengths on the same project to produce the best result we can.

Something like that anyway!

Cheers Xenakios!

__________________
REAPER? Oh yes...

Last edited by Deric; 04-10-2008 at 12:37 PM. Reason: Typo.
Deric is offline   Reply With Quote
Old 04-10-2008, 12:34 PM   #14
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,649
Default

Deric, a good idea to learn the programming language on a more general level first! I should do that myself...

I can code Delphi (basically Pascal with LOTS of extensions for Windows graphics etc spesific stuff) pretty well, but I am a LOT less skilled with C/C++ and direct win32 APIs programming. But I just could not resist the temptation and try some C++ programming right away when the Reaper Extensions SDK was more larger and allowed new nice things... So now I am bit confused and frustrated with lots of stuff...
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.