Title: For those using Dev-C++
Dragon - August 14, 2003 10:24 PM (GMT)
If you are writing Windows applications using Dev-C++, I found a way to greatly reduce the compiled program size. When starting a new project, specify a C project, and not a C++ project.
Note: Only do this for Windows applications (maybe DLLs, etc., too, but I haven't tested that).
Candyman - August 14, 2003 10:35 PM (GMT)
so it wont cause compile time or run time errors when making and using the program, and pretty much ignores your using C++ instead of C? I can't imagine how this works but I'm not gonna argue :) cool and thanks a lot, a simple program i made was 1.2 megs, and it was no more than 50 lines!
Dragon - August 14, 2003 10:38 PM (GMT)
No, Windows applications are written in C. That's why you use #include <windows.h>. C++ headers drop the .h at the end. That's why it wouldn't work with console applications because you are programming in C++.
Candyman - August 14, 2003 10:40 PM (GMT)
ah okay, i think i understand, as long as you dont mean I have to program in C, but still have the size of a C project I'm happy.
Dragon - August 14, 2003 11:52 PM (GMT)
When you are programming a Windows application, you ARE programming in C. Correct me if I'm wrong.
dr voodoo - August 15, 2003 09:16 AM (GMT)
| QUOTE |
| When you are programming a Windows application, you ARE programming in C. Correct me if I'm wrong. |
Yes and No, as far as I know all functions and types defined in the windows header are C and C++ compatible so Win32 programming is actualy C. But no program is exclusively Win32! As soon as you use a single varible you left Win32 and you have to make sure that your code is C compatible!
Example (compile as console):
This is no valid C prog:
| CODE |
#include <windows.h> int main() { MessageBox(NULL,"Hello","Hello",MB_OK); int a=0; system("pause"); } |
It should be:
| CODE |
#include <windows.h> int main() { int a; MessageBox(NULL,"Hello","Hello",MB_OK); a=0; system("pause"); } |
Because in a C function you have to declare all variables before you do anything else in the function.
FHCandyman - August 15, 2003 01:25 PM (GMT)
ahhh ok. I didnt know that(am not into win32 yet). Thanks for clearing that up :D
myork - January 21, 2004 04:58 PM (GMT)
The real reason your program is smaller is that the C++ runtime library (C++RL) is not being added to your program.
The C++RL is very big.
An alternative would be to build a C++ project but not compile in the C++RL. It is possable to get your compiler to generate code to dynamicall load the C++RL when the program executes (there are dll versions of the C++RL).
Unfortunately I am not MSVC expert so can tell you the options.
FrozenKnight - January 22, 2004 11:26 AM (GMT)
Whither you are programming in C or C++ in windows it doesn’t matter to windows it's all the same. you are still using the windows api which I believe were coded in a combination of asm, C and C++. and I don’t see now you can call a program of 1.2 megs an accomplishment most of my programs are 40 - 200k mostly depending on what I include into the project. if you really want to talk about small programs then look at asm. if you get good at it you can code windows programs that are measured in bytes :)
I use Visual C++ and I have one MFC program I wrote that is well over 400+ lines and it is just 40 kb (150 with MFC DLL's included by switching to API I was able to keep the 40KB size with no DLL dependencies)