|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Resident AMD enthusiast
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
|
First I'll admit all the programing I've ever done was a little dice program in Basic on a 286 years ago, so I don't really know exactly what I'm talking about.
However I got an idea. I eventually want to learn C++, but until then I'm thinking about ways to make my soon to be C++ experience better. My idea is a program which would write it's own programing, sort of. Like for instance you want to write a program to run x motor for x seconds. You would write the first program which would run the motor with spots to insert the x variable. Then you use the second program which would copy the first program into the program your working on. For instance "Program: run motor 1 for 10 seconds, run motor 2 for 25 seconds..." would copy the motor control program, with the appropriate numbers. This would be very useful, like if you wanted to tell something to rotate x degrees, letting the program do all the calculations for you. Basically just copying and pasting, but perhaps a little easier. Although about this idea? Logan
__________________
Main: Gigabyte GA-770T USB3 - Phenom II 840 - 4GB DDR3 - Radeon 5750 1GB HTPC: MSI K9N6PGM2-V2 - Athlon II 250 - 4GB DDR2 - Radeon 5670 512MB HTPC: Zotac GeForce 6100E-E - Athlon X2 5800+ - 4GB DDR2 "Play a Windows CD backwards and you'll hear satanic voices, thats nothing, play it forwards and it installs Windows." |
|
|
|
|
|
#2 |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
You'd be better off using functions; it would compile to a much smaller program -- in C++ it would look something like this, for your example:
Code:
void RunMotor(int motorID, int seconds); // prototype of the function
int main(){
RunMotor(1,10);
RunMotor(2,25);
}
void RunMotor(int motorID, int seconds){ // body of the function
// here would be the code to do the motor
}
__________________
Paul M. Victorey ------------------ I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk. |
|
|
|
|
|
#3 |
|
Resident AMD enthusiast
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
|
I almost forgot I had this thread to watch...
So what I speak of is already implemented? except, without modifying a program, then you would have to type the motor controll part over for every program? I think that my Idea would still have some use. It could probbably be very simple, and then you could re-use again and again with far fewer keystrokes. Not to mention be easier to program(hopefully not too esy though). Say you wanted to make an arm, and program it to reach out to 100 different posistions on command, then you would need about 100 different programs, which I think is where my idea would prove usefull. Logan |
|
|
|
|
|
#4 |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
If I had a problem with 100 different positions, I'd only write one program, with one function to move the hand; it would take as an argument the number of the position (0 through 99) that I wanted the hand to move to.
So that it actually knew where the position was, I would use a lookup table to specify where the 100 positions were. Really though, there is no difference between what you say and having a function which is declared as "inline". Normal functions are better, usually, because the code is only included in the executable once. Inline functions are a tiny bit faster, though. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|