• Welcome to Jose's Read Only Forum 2023.
 

Very Interesting

Started by James C. Fuller, September 20, 2016, 07:13:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

James C. Fuller

While working on the CWindow port I discovered something very interesting!!
As I mentiond in the CWindow post: http://www.jose.it-berater.org/smfforum/index.php?topic=5141.0
I came up with a solution to only include source that is used in an app.
I had just included a very large block of code in my test app but had forgotten to apply the $IFUSE/$ENDUSE to it. Because I was testing with TCLib I was closely monitoring the sizes of the exe files created. I noticed the size was the same as the previous build without this block of code included. What??
Something strange is going on!!

It turns out Visual Studio 2015 Community only includes code used in an app.
I thought at first it was something missing from my self learning of c/c++ but it turns out it is MS only as far as I can tell.

I see this as maybe having a big shift on c/c++ coding especially if one is using self made libraries or those with source included. With libraries you really need to watch your granularity. For the best case senerio, you compile each function to it's own obj file before adding it to the "lib" file. Any small change to the source requires a rebuild of the whole library.

I intend to keep using $IFUSE/$ENDUSE for bc9Basic as it keeps the c/c+ translation source a lot neater.

James


/*
* a test of the default optimization of the Visual Studio 2015 Community
* Microsoft (R) Incremental Linker Version 14.00.23506.0
* vs other compilers: NUWEN, TDM, Pelles, and Tiny C
* compile and link with what ever options you normally do as this is not
* an actual comparison of sizes between them but rather what is compiled
* and included in the executable. note the exe file sizes after the build.
* now comment out the F2 - F5 function bodies and the calls to them
* in the main() function along with the respective printf's and compile again.
* note the sizes.
* now uncomment the F2 - F5 function bodies and build again.
* You should see the VS build is the same size as the 1 to 1 build
* where the other compilers build sizes are not.
*/

#include <stdio.h>
#include <stdlib.h>
int F1 (int a, int b)
{
    int i;
    a += 10;
    b += 10;
    i = a + b;
    printf("%s%d%s%d\n", "Hello From F1-> ", a, " ", b);
    return i;
}

int F2 (int a, int b)
{
    int i ;
    a += 20;
    b += 20;
    i = a + b;
    printf("%s%d%s%d\n", "Hello From F2-> ", a, " ", b);
    return i;
}

int F3 (int a, int b)
{
    int i;
    a += 30;
    b += 30;
    i = a + b;
    printf("%s%d%s%d\n", "Hello From F3-> ", a, " ", b);
    return i;
}

int F4 (int a, int b)
{
    int i;
    a += 40;
    b += 40;
    i = a + b;
    printf("%s%d%s%d\n", "Hello From F4-> ", a, " ", b);
    return i;
}

int F5 (int a, int b)
{
    int i;
    a += 50;
    b += 50;
    i = a + b;
    printf("%s%d%s%d\n", "Hello From F5-> ", a, " ", b);
    return i;
}

int main ()
{
    int i;
   
    i = F1( 10, 20);
    printf("%s%d\n", " i = ", i);
 
    i = F2( 10, 20);
    printf("%s%d\n", " i = ", i);
   
    i = F3( 10, 20);
    printf("%s%d\n", " i = ", i);
   
    i = F4( 10, 20);
    printf("%s%d\n", " i = ", i);
   
    i = F5( 10, 20);
    printf("%s%d\n", " i = ", i);
   
    system("pause");
}



James C. Fuller

I found out the why's and an alternate how-to !

The why in this particular case (and most others using bc9Basic) appears to be vc only.
All source is in a single file and only routines called are compiled and linked to the exe. If I move the functions to a file by themselves and "#include" that file,  all of them are compiled and linked to the exe.

But if we compile the func file to an object file using /Gy and then link the obj file only the funcs called are included in our exe.

There supposed to be a similar way for gcc but I am not sure if it works for windows.

James