Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 01-06-2002, 02:26 PM   #1
Resident AMD enthusiast
 
Colonel Sanders's Avatar
 
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
Question Crazy programming idea

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."
Colonel Sanders is offline   Reply With Quote
Old 01-06-2002, 02:45 PM   #2
Member (12 bit)
 
Paul Victorey's Avatar
 
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
}
You can even create libraries of functions, which you could call from any program you create.
__________________
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.
Paul Victorey is offline   Reply With Quote
Old 01-09-2002, 04:31 PM   #3
Resident AMD enthusiast
 
Colonel Sanders's Avatar
 
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
Colonel Sanders is offline   Reply With Quote
Old 01-09-2002, 10:17 PM   #4
Member (12 bit)
 
Paul Victorey's Avatar
 
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.
Paul Victorey is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:50 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2