The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
size of executable
Discuss size of executable in the C Programming forum on Dev Shed. size of executable C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 21st, 2002, 11:10 AM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: England, UK
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
size of executable
Hi, I've just written my first few apps and they seem to be quite big. One for instance is 105kb, when all I'm including is <string>
and <fstream> (the source file itself is only 40 or so lines). Is this just how it is or can the compiler somehow remove unneeded functions? I'm using dev-c++.
While I'm here, I want to change a files extension so I've done this:
Code:
while(file_name[a] != '.'){
out_file[a] = file_name[a];
a++;
}
out_file[a] = '.';
a++;
out_file[a] = 't';
a++;
out_file[a] = 'p';
a++;
out_file[a] = 'l';
a++;
out_file[a] = '\0';
a++;
which seems a little odd, is there a tidier way. BTW I come from PHP and pointers scare me so I've no idea how I even managed that, so go easy.
|

November 21st, 2002, 11:16 AM
|
 |
Contributing User
|
|
Join Date: Dec 2001
Location: USA
Posts: 286

Time spent in forums: 7 m 23 sec
Reputation Power: 12
|
|
|
Are you building debug binaries (bigger) or release binaries (smaller)?
__________________
Jon Sagara
"Me fail English? That's unpossible!"
|

November 21st, 2002, 11:24 AM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: England, UK
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
normal, it comes out at 280 with debug on.
I also have the optimize options on ( -g3 -fexpensive-optimizations)
|

November 22nd, 2002, 10:11 AM
|
|
Contributing User
|
|
Join Date: Oct 2002
Location: Flint, MI
Posts: 328
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 11
|
|
include string and fstream will bloat the code considerably. These include files typically contain most of the code necessary to implement the class.
You can also simplify the code, by using C functions instead of C++ classes:
Code:
#include <string.h>
#include <stdlib.h>
char* change_extension(char* filename) {
char* outfile;
char* extension;
outfile = (char *)calloc(1, strlen(filename) + 3);
strcpy(outfile, filename);
extension = strchr(outfile, '.');
if (extension)
strcpy(extension, ".tpl");
else
strcat(outfile, ".tpl");
return outfile;
}
The standard C libraries have a great set of functions for basic string manipulation and navigation. I usually find them to be easier to use than the C++ equivalents, with the exception of the search and replace capabilities of C++ strings.
__________________
Clay Dowling
Lazarus Notes
Articles and commentary on web development
http://www.lazarusid.com/notes/
|

November 22nd, 2002, 11:12 AM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: England, UK
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
Thanks, I think I just about get that piece of code you posted after some thought.
This line:
Code:
outfile = (char *)calloc(1, strlen(filename) + 3);
I understand to be allocating some space for the filename and adding some incase there's no extension (would that not need 4 then?)
As to my first question, I did think about maybe trying C headers instead although I will need to read up on them (I tried changing to string to string.h and my compiler was not happy). All I'm doing with string is holding the line from the in file, checking it and then sending it out so maybe I can do something else and use C file I/O instead and see if that comes out smaller. Cheers then I'll give that a go.
|

November 22nd, 2002, 11:20 AM
|
|
Contributing User
|
|
Join Date: Oct 2002
Location: Flint, MI
Posts: 328
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 11
|
|
|
You are right about the size: 4 bytes, not 3.
The calloc function, as you indicate, allocates memory. It also initializes all members to 0, which can save problems. The parameters to calloc are the number of records and the size of those records.
Elsewhere in your program (but not in this function), you'll want to free() the memory after you're done with it, to prevent memory leaks.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|