Making use of the preprocessor?
-
One of my classes keeps a lookup-table that is based on a few constants
#define
:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:m_table[256] = {
0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
...
};I have a function that computes the table and prints it to standard output, so if I change one of the
#define
:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
-
One of my classes keeps a lookup-table that is based on a few constants
#define
:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:m_table[256] = {
0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
...
};I have a function that computes the table and prints it to standard output, so if I change one of the
#define
:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
nope, the preprocessor isn't that capable. but, take a look here: http://www.codeproject.com/string/CXR.asp i wrote a little system to do string encryption as part of the build process (roughly similar to your table generation). what i do is add a file to the project that causes VC to do a pre-build step. that pre-build step generates a source file (by calling off to a separate EXE), which is then compiled into the app. -c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
-
One of my classes keeps a lookup-table that is based on a few constants
#define
:d in the header. If one of the constants change before a recompile the table has to be recomputed, but otherwise it is defined as a constant:m_table[256] = {
0x00000000, 0x6750096, 0xEEEE4455, 0x45DF5C75, 0xB6662D3D, 0x23EE4521,
...
};I have a function that computes the table and prints it to standard output, so if I change one of the
#define
:d constants I can compile, run the function, cut-and-paste the table back to my sourcefile, and finally recompile.. Is there any way to make the preprocessor do this? The table-generating function is not simple enough to make into a macro.. Any suggestions? Thanks /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
If the function is not very complex, you can convert it to a constant-time template by using a technique called template metaprogramming. If you post the code maybe I can help you with it. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
If the function is not very complex, you can convert it to a constant-time template by using a technique called template metaprogramming. If you post the code maybe I can help you with it. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Thanks! Googled for the term and found some nice pages. I'll try to do the conversion myself first - it will be a nice introduction to the concept. But I hope you don't mind if I ask you for help if I get stuck... /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
-
Thanks! Googled for the term and found some nice pages. I'll try to do the conversion myself first - it will be a nice introduction to the concept. But I hope you don't mind if I ask you for help if I get stuck... /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
Good luck. TMP is an amazing technique, if difficult to tackle at first. Don't hesitate to ask for help. PS: If you're succesful, your case could be a nice introduction article to this technique here in CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
nope, the preprocessor isn't that capable. but, take a look here: http://www.codeproject.com/string/CXR.asp i wrote a little system to do string encryption as part of the build process (roughly similar to your table generation). what i do is add a file to the project that causes VC to do a pre-build step. that pre-build step generates a source file (by calling off to a separate EXE), which is then compiled into the app. -c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
Seems like a reasonable solution. Joaquín M López Muñoz also had an interesting suggestion. I'll first take a shot at template metaprogramming (I like to try out concepts new to me), but if that fails I'll go with a pre-build step. Thanks /moliate
The corners of my eyes catch hasty, bloodless motion - a mouse? Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours