[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Just started my first C++ class(I study math) and I'm getting

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 2

Just started my first C++ class(I study math) and I'm getting something weird. I built a code for a simple program for an exercise and the .exe file is 1900 kb, then extended it for the rest of the exercise and the new .exe file is 600 kb while the program does EXACTLY what the first one did, plus more. Why is this happening?
>>
If you just started programming, don't ask questions that you don't want to know the answer to.

Now I'm not calling you stupid, but are you positive the first program was 1900kB and not 1900B?

The only other likely explanation would be that you were using some method from a library that had a lot of overhead, and that you might have removed something on the revision that you thought was minor but to the compiler was actually large.

The only way to know for sure would be for you to post both pieces of code here and I or someone else will look at it. For this reason I really wish we had [code] tags but alas they are only on /g/. You could ask them as well but they'll be dicks about it.
>>
http://mathb.in/54196?key=9ba1e2769df8a0c00263062890de8ce2791b3b08


http://mathb.in/54197?key=f212324d6236f0174a96bac37d4cd822db01bdc0

Compiled it with dev C++.
>>
>>7949984
All my single backslashes got double for some reason. Probably mathb.in's fault.
>>
>>7949986
I've compiled it and it was 900 Bytes, what compiler are you using, and are the arguments?

I can't see any reason for it to have 1900kbs of size, how long does it take to compile?
>>
>>7949986
I'd have to get my other machine out and compile myself to know for sure but I'm guessing it's something to do with the compiler you're using, are you using g++? Might be related to the fact that you're saying return(0); and return(1); as if return were a method and not a keyword. You're supposed to really just use return 0; at the end and you can return any other integer if the intention is to throw an error but if you're writing int main() test programs that's not really necessary.

Also, unrelated to your issue but stop naming your variables with capital letters. By convention, capital letters are constants and prefixed with the const keyword.
>>
>>7950124
I'm using Dev C++'s compiler because that's what my class uses. I was playing around to see what would change if I entered return(1) instead of 0, didn't notice I changed that until now.

>>7950115
Really fast, is it supposed to compile slowly?
>>
>>7950160
it should compile in less then a second. Problem is probably some inclusion or compiler directive. Did you do a debug or release build?
>>
>>7950180
The dev C++ debugger doesn't seem to work, I bet I'm making a rookie's mistake though. I tried a workaround to debugging by printing each value and the sum in the loop "for" because I had a minor problem but I fixed that. What's a release build?
>>
>>7950258
To debug a program like this, the compiler needs to include in your compiled program (the .exe) all sorts of auxiliary information, which makes the program both much larger and considerably slower. Because of that, the compiler can --as a configuration option-- either build the fast-and-small version that is suitable for practical use (the "release build"), or the slow-and-large version that you can use with debugging tools (the "debug build"). The difference MAY be the cause of the size difference that you are seeing, and it may also be the reason you can't use your debugging tools.
>>
>>7949984
>>7950258

>dev C++

Please don't use this. It's literally over a decade out of date, and it was shit even a decade ago. Just use command line and use clang/GCC, or use a decent IDE if you want (Visual Studio (2015 Community is free) is a good one for larger projects if you're on Windows, has a nicely integrated debugger, profiler, etc too, but it's pretty big). Even the piece of shit that is Code::Blocks is better than Dev-C++ (and is also fairly small). There's also qtCreator as an IDE, which is a bit bigger.
>>
Also are you in highschool, or university? I've only ever seen dev-C++ used in highschool programming courses, not university. Most universities I've seen don't use an IDE, or if it they do it's something like eclipse/qtcreator.
>>
>>7949953

The size of an executable is quite variable from my experience with MSVC++ compilers. These compilers have options to optimize (for speed, for size, or full) the code based on preferences and interest in compilation time. I can get my executable to grow considerably if I choose particular compiler settings.

Also, due to compiler short cuts you could see changes in executable size, though I can't imagine this would account for such a large change in file size.
>>
>>7949984
>declaring all the variables at the top
>declaring variables uninitialized only to be immediately initialized in the next line

Jesus Fucking Christ, it is NOT 1989! Stop living in the goddamn past.
>>
File: 1246752979641.jpg (37KB, 500x453px) Image search: [Google]
1246752979641.jpg
37KB, 500x453px
>>7949984
>I=0;
>cout<<"ARITHM["<<I<<"]=";
>cin>>ARITHM[I];
>ATHR=0;
>while (ARITHM[I]!=TERMAT){
> ATHR+=ARITHM[I];
> I++;
> cout<<"ARITHM["<<I<<"]=";
> cin>>ARITHM[I];
>}
>N=I;
>cout<<"N="<<N<<"\n";
>for (I=0; I<N; I++)

Why the fuck did you use I instead of directly using N? WTF
>>
>>7949953
With default settings (on WIndoze at least with g++ 4.5.2) I get an exe size of just over 1MB with a standard hello world program. Don't know what extra libs you are linking (debug build perhaps?). Looks pretty standard.
>>
>>7950574

A static library on both Windows and Unix is a collection of .obj/.o files. The linker looks at each of these object files and determines if it is needed for the program to link. If it isn't needed, then the object file won't get included in the final executable. This can lead to executables that are smaller then the library.

Thus, libs would have no effect here.
>>
your code looks ugly
btw stop using dev-c++. it's buggy and bloated. switch to g++
>>
>>7950720
Ah! The eighth and ninth dwarves: Buggy & Bloated. ;-)
>>
>>7949953
>not saving old copies of files with each revision
Now we'll never know.
>>
>>7949953
you shouldn't make your variables all caps unless they're constant values, not code breaking but just common convention.
>>
>>7951153
Yea I don't know what I changed but they all got 600 kb now.
Thread posts: 22
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.