| ggarciabas (6) | |||
|
Hello, I created a simple file to calculate a bisection and I had problems with the #define. I used this structure:
And in the function bisseccao () I have fa, a simple variable and I want that variable receive the result of the f1a ( defined on #define), but the result is wrong. This is correct? If not, could some one help me, I need to do something like this, I need to inform the equation and calculate them. Thank you, GGarciaBas | |||
|
|
|||
| kbw (5520) | |
| That isn't quite right in principle. But rather than wasting time fixing that, as you're using C++, why not use functions? You can inline them if you feel you need them to be inline. | |
|
|
|
| Stewbond (1842) | |||||
You can define them as a macro this way:
Then use them like so:
But kbw is right, it's better to use functions than macros. Macros can cause some strange things. Example: using this macro: #define max(a,b) (((a) < (b))?(b):(a)) like this: max(i++, 0);will give you this: (((i++) < (0))?(0):(i++));i get's incremented twice! | |||||
|
Last edited on
|
|||||
| ggarciabas (6) | |
|
Thank you guys. Can I get to the user's equation on running the program and use then to calculate a value of any number, I said, define the equation to the variable in the program execution? GGarciaBas | |
|
|
|
| EssGeEich (1007) | |||||
| |||||
|
Last edited on
|
|||||
| ggarciabas (6) | |
| Thank you. | |
|
|
|
| Cubbi (1927) | |
Technically, __e cannot be used in a portable program, with or without a #define: it contains two underscores, and all such identifiers are reserved.
| |
|
|
|