![]() |
| | #1 |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Help with making a Math Expression DLL I'm looking at creating a set of math expression functions. Here's a quick example of what i want: Code: int i = 0; mathexpr em = MathCreate(1); //Creates a unique handle, sets the initial value to 1 MathAdd(em,10); //Makes the expression add 10 to the value. Not calculating yet. MathSub(em,6); //Makes the expression subtract 5 from the value. Not calculating yet. i = MathEval(em); //Will evaluate the expression "1+10-6" returning 5. MathDestroy(em); //Destroys an expression, releasing it's handle, and freeing the memory used. //Other functions would include MathSet(em,i); //Sets the value of the expression to i, clearing the whole expression. MathDiv(em,i); //Divisions MathMult(em,i); //Multiplication MathOr(em,i); //Bitwise Or Operation MathAnd(em,i); //Bitwise And Operation MathXor(em,i); //Bitwise Xor Operation MathPow(em,i); //Would add pow(MathEval(em),i) //This is just the things i could brainstorm, any math function i deem usefull should be added. //Also, if possible the different Math* should return an id, then a function called MathRemove(m) //could be used to remove a certain step from an expression. Example from above: int i = 0; mathstep m = 0; mathexpr em = MathCreate(1); //Creates a unique handle, sets the initial value to 1 m = MathAdd(em,10); //Makes the expression add 10 to the value. MathSub(em,6); //Makes the expression subtract 5 from the value. MathRemove(em,m); //Removes the "+10" part of the expression, leaving "1-6". i = MathEval(em); //Will evaluate the expression "1-6" returning -5. MathDestroy(em); //Destroys an expression, releasing it's handle, and freeing the memory used. Please know that i'm not asking for code, i'm asking for knowledge, ideas, usefull reading and really any usefull info. |
| MindWorX is offline | |
| | #2 |
| int x = *((int *) NULL); Join Date: Jul 2003 Location: Banks of the River Styx
Posts: 902
| What would be the advantage of what you posted over just i = 1+10-6 ? Otherwise, it sounds like you're looking at creating a library. To start, just write the functions as you would normally, keeping them in a separate source file(s). Later, you could look into wrapping them into a DLL.
__________________ long time; /* know C? */ Unprecedented performance: Nothing ever ran this slow before. Any sufficiently advanced bug is indistinguishable from a feature. Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31. The best way to accelerate an IBM is at 9.8 m/s/s. recursion (re - cur' - zhun) n. 1. (see recursion) |
| Cactus_Hugger is offline | |
| | #3 |
| Algorithm Dissector Join Date: Dec 2005 Location: New Zealand
Posts: 2,737
| Could you please help out by explaning the purpose of this?
__________________ My homepage Advice: Take only as directed - If symptoms persist, please see your debugger |
| iMalc is offline | |
| | #4 |
| Registered User Join Date: Sep 2001
Posts: 752
| To be honest, what kind of help you need depends a lot how good a grip you have on the fundamentals of programming. Are you familiar with trees? That seems to be the natural way to go with this.
__________________ Callou collei we'll code the way Of prime numbers and pings! |
| QuestionC is offline | |
| | #5 | ||
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Quote:
Read above. Quote:
| ||
| MindWorX is offline | |
| | #6 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,295
| Try and conform to C89, see the C89/90 draft as it's more portable. Before you dive into coding it, design it - look at linked lists and binary trees as QuestionC suggested. From there it should be smooth sailing. |
| zacs7 is offline | |
| | #7 | |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Quote:
Code: struct node {
int operation; //Would be set to a number representing the operation, 0 = add, 1 = sub, 2 = div, etc etc.
long val;
struct node *next;
};
Btw, what's C89? | |
| MindWorX is offline | |
| | #8 |
| Registered User Join Date: Sep 2001
Posts: 752
| C89 is the traditional C standard which it is safe to assume any given compiler supports.
__________________ Callou collei we'll code the way Of prime numbers and pings! |
| QuestionC is offline | |
| | #9 |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Okay, so C89 would be like the math.h and stdio.h ? Atleast, that's the ones i assume any compiler should have. Is there a list of the C89 standard? |
| MindWorX is offline | |
| | #10 |
| Registered User Join Date: Sep 2001
Posts: 752
| The document defining the standard is pretty heavyweight and not free. Honestly, there is not a good reason to worry about it for the purposes of this project.
__________________ Callou collei we'll code the way Of prime numbers and pings! |
| QuestionC is offline | |
| | #11 |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Okay, well, i'll try and do it with a linked list, and the process as i suggested earlier. I think it's going to work, and i'll get to learn about linked lists in the process. |
| MindWorX is offline | |
| | #12 |
| Registered User Join Date: Sep 2001
Posts: 752
| This could actually be useful for implementing a routine to perform bulk math operations... Code: // :1 is a placeholder for the variable
math_transform("5 + 3 x :1 + 7", input, output, num_elements);
__________________ Callou collei we'll code the way Of prime numbers and pings! |
| QuestionC is offline | |
| | #13 | |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| I seem to have run into a problem already Code: #include <stdlib.h>
int main()
{
int *ptr = malloc( sizeof(int) );
return 0;
}
Quote:
http://www.cprogramming.com/tutorial/c/lesson6.html | |
| MindWorX is offline | |
| | #14 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| Quote:
| |
| brewbuck is offline | |
| | #15 |
| Registered User Join Date: Nov 2006 Location: 82.192.160.50
Posts: 17
| Don't know, that's what i've always done. But seems to work now. How will this affect my project if the rest of it is named cpp, and this file is going to be a .h file in the end? Should all my files be c then? Or should i do the linked list in c++ instead? |
| MindWorX is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please Help - Problem with Compilers | toonlover | C++ Programming | 5 | 07-23-2005 10:03 AM |
| Expression Evaluator Contest | Stack Overflow | Contests Board | 20 | 03-29-2005 10:34 AM |
| .lib vs .h vs .dll | Shadow12345 | C++ Programming | 13 | 01-01-2003 05:29 AM |
| Passing parameters from VB to C++ through ActiveX DLL | torbjorn | Windows Programming | 0 | 12-10-2002 03:13 AM |
| Help! Program to evaluate expression... | Unregistered | C++ Programming | 7 | 02-19-2002 06:20 AM |