C :: How To Exclude Function Dynamically On Compile Time
Mar 6, 2013
I am working on a project, where I have to be able to exclude some code fast and dynamicly at compiletime.
I got a scheduler running and actually I just want to remove some of the tasks from it - but at compile time so that the code wont take up space in my microcontroller.
I know that I can use macros like #ifdef #endif etc. But I think that method makes the code unreadable and complicated.
How to archive such functionality a more elegant way?
As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.
Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?
My question is this: Is it possible to determine where functions are stored at compile time, so that at run time you can pass the memory address as a pointer to the interrupt handler so that it can directly call the function at memory location 'X'?
The newest project I'm working on would require to either somehow capture these addresses or to find a work-around so that instead of passing the pointer to the interrupt handler, the software would then need to be able to be non-interruptable.
Would there be anyway for the compiler, or the language, to provide a unique ID during compilation?
I've been using UUID generators, but I've always found the approach of copy pasting from a program to code to be kind of... limiting. If I want a random number, can't the compiler guarantee this for me?
It already does the same thing for anonymous namespaces, so...
Consider: Code: template<unsigned int N> class Test { private:
[Code]....
I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop). I only tested on MSVC.
So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.
How do I set the size of a member array via the class constructor if I know the size at compile time. I can do this with templates, see below, but this leads to code bloats, I think.
So one class declaration but objects with different array sizes.
Can't use constexpr. Can't use STL. Can't use new.
#include <iostream> using namespace std; template<int T> class MyArray { private: int array[T]; public: int getSize()
I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.
How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?
Code: typedef struct token { int tokenType; // what token is that int tokenCode; // the code of a function if applicable char *tokenString; // Source token double tokenValue; // if token is a number
[Code] .....
I got several warnings and erros, is it possible to declare a table like that ? What's the correct way to declare it ?
Problem: My code works perfectly and I only need to solve one issue. When I am calculating the average, how do I exclude the min and max values from the array?
My code:
#include <iostream> using namespace std; int main(){ float a[9]; int x; int sum = 0; for (x=0; x<9; x++) {
The below code compiles without error using VS 2012 but with g++ 4.1.2 I get this error:
Code: main.cpp: In function 'int main(int, char**)': main.cpp:37: error: no matching function for call to 'StringHelper::stringToNumeric(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
Here is the code:
#include <string> #include "boost/lexical_cast.hpp" using boost::lexical_cast; using boost::bad_lexical_cast; class StringHelper {
[Code] ....
This is part of a larger program so in reality StringHelper has more static functions but this example does produce the error the same as the code when in the larger program.
To get it to compile under g++ I had to assign the return value from substr() to a string and pass that string to stringToNumeric. Why do I have to do this for g++ and not VS? Do I have something wrong with my template function that g++ is calling out and VS is not?
Is there a way to call a function whose name is defined in a file-stored-list?
In other words: The caller doesn't know in compile time the name of the function.
I'm not talking about polymorphism.
The problem is: I have a list of function names stored in a file, that may change every now and then, and I'd like to call them in the sequence they appear in that list.
I need a variable that will just hold a function that I can change in the middle of the application, even to different function type with different amount of parameters ... is this even possible? At the moment I have this
How do I point this one to the variable special, when I want to call it like that (or something similar)
(reply.special)("test string");
is this even possible? if so, how? i tried to create function pointer (didnt compile at all) or use template (neither did this) and how to do this as I discovered functional lib just a while ago.
This a very simple program I created because I dont understand how do this. My goal is to be able to use the pointer *s5 throughout the program. For example I would to like to call other functions and pass that pointer through the function. I understand the dynamic allocation and pointers for the most part but Im confused here because the "new char[20]" variable will die after the function and I dont want it to.
#include <iostream> #include <cstdlib> #include <cstring> using namespace std; void testArray ( char *s5 ); int main ( int argc, char *argv[] )
In a program I'm working on now, i need a milti-dimensional array. To save space, I used dynamically allocated array by using pointers, something like this-
int *arr; arr=new int[col*row];
And now i need to pass this array in a function. What are the parameters in the function declaration statement and at the function call statement?
I have two projects (Projects A and B). Project A is a dll project, defining a function called "regex".
Project B dynamically loads this DLL, and calls Project A's "regex" function via LoadLibrary/GetProcAddress.
Regex takes a pointer to an std::vector (std::vector<std::cmatch>).
When debugging ProjectB, I can see that, within the code from ProjectA (in the "regex" call), a loop that loops through the elements of the vector outputs all the elements in the vector to console as expected. But the loop in ProjectB ( which executes after ProjectA), which also loops through the vector, and, is supposed to output the elements of the vector, outputs empty strings, not, as I would expect, the same strings (which contain results), as in the loop in Project A.
How is this happening. Does this have anything to do with it being a DLL, and, maybe, somehow values/memory addresses (or something similar) of the vector/its elements being destructed across the Projects/Dlls?
I've been trying to get my matrix multiplication program to run a few different ways. My assignments wants me to run it statically using chunks, but we're not supposed to use OpenMPs scheduler. So I'm not sure how that's possible. And secondly, we have to run it dynamically using locks/unlocks.