mmm not exactly. If I remember correctly they are allocated in their own memory space. Cannot remember the name though.. have to look it up. Regarding whether or not is a good programming standard or not...well...it depends on how to use them. They should be avoided if another way is possible and good OO techniques should be used instead. Sometimes they are usefull though and their use might be required. Of course I wouldn't use static functions all over the place because static functions have their limitations and so they should be used with care.
Emmanouil
Posts
-
static function -
static functionHowever you have to take care of static functions and use these only if you are sure that they fit to your design. An alternative way to do this is to just derive the classes that needs your functions from the class they belong to. i.e class A{ public: void funcA(); void funcB(); }; class B: public A { // inherits class A // this class now can use the funcA and funcB as its own }; Its basic OO C++ :-)
-
static functionYes you can use static functions for that. You can have like a utility class that you can put helper functions in there. Example usage will be like the following code: //======================== class A{ public: static void myprint(){ printf("static hello ! \n"); } }; class B{ public: void func(){ A::myprint(); // Here you call the static myprint without having to create an object of class A } }; int main() { B *poB = new B(); poB->func(); A::myprint() // Again, you can call myprint with no object creation } //======================== The output of this will be : static hello! static hello! Hope that helps :-)
-
How can I create a generic pointer?you just write: void * myPntr;
-
Malloc & Page FileYes I agree with you on the interprocess communication but sm was only a suggestion. Maybe the solution requires the existence of two separate processes for some reason, then shared memory maybe a good choice. I am not arguing it will be the best though :-)
-
Malloc & Page FileHave you considered using shared memory? There are implementations of circular buffers using shared memory and they are really fast. If speed is what you need I thing you should consider this solution.
-
True or False Flags: best practicesI believe you are right. In terms of readability if the language you are using actually supports the boolean type and the true,false keywords then it means is recommended to use them. In certain cases this will not be true. For example C did not have a book type until C99 came out and then C++ provided bool type and true/false keywords as a built in feature. If you do use C++ then it is recommended to use the true/false type since they are provided. Even in C , it was a good coding practice to #define the keywords TRUE and FALSE to 1 and 0 respectively to provide a more readable code. Just my humble opinion :-)
-
graphics.hYou cannot find graphic.h when you try to compile with visual studio because it is a borland extension. Microsoft uses a different one, so is gnu etc etc. Try compiling with Borland Builder it should work... Downloading someone's source code and trying to compile it with vis studio is not enough. You have to take into account which platform was used to write the program. For example you could try download a game which was written for Linux and try to compile it in visual studio. It will most certainly fail because it will use libraries and extensions that were only developed for the linux system.
-
taking variable value to another classWhy dont you derive one class from another so you can use the function y from class A for example? Have you declared pointers inside each class?
-
How to find out the size of a structure without using sizeofI agree. sizeof will return different size for the same structure if executed in different platforms i.e linux vs windows and thus different compilers. This is due to padding and alignment of members for optimization purposes in the memory. There are macros or compiler options that can be used to eliminate padding i.e to use 1 byte padding always. If i remember correctly this will be the "pack(1)" macro and in Visual C++ the compiler option /Z1 (I think) can be used to force 1 byte padding. This will give more consistent results with sizeof... :-).
-
need a similar function as "getchar()"An alternative way is to use the select() call (only if you use linux/unix platform). select will wait for a file descriptor to become active and read the data from this file descriptor. I assume you can establish a pipe interface with STDIN and then use select to monitor your fd. you can put select in a while loop to monitor the fds continuously and maybe fork() this function if you want control back...