[cfe-dev] Binary size when using std::function with lambda expression

Cyril Makloufi via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 8 02:45:06 PST 2021


Hello,


When using std::function instead of function pointer (see the sample of code) on Mac, we get a huge difference between size of generated binary (80ko when using function pointer and 157ko whit std::function).

I use Xcode to build debug with -O0 -std=gnu++14 and libc++.

It doesn't seem to have the same result on windows or linux.

Is it something normal ?


Here's the code sample :


#include <iostream>

#include <functional>



int main(int argc, const char * argv[]) {

    std::function<void()> f = [](){std::cout << "LOG2\n";};

//    void (*f)() = [](){std::cout << "LOG3\n";};



    f();



    return 0;

}



Thanks,

Cyril

[cid:image0b65ab.JPG at a378ba69.48ac0a90]
Cyril Makloufi
Développeur
Email : Cyril.Makloufi at 4d.com<mailto:Cyril.Makloufi at 4d.com>
Web :   www.4d.com<http://www.4d.com>

4D SAS
66 route de Sartrouville
Parc Les Erables - Batiment 4
78230 Le Pecq - France
Standard :      +33 1 30 53 92 00




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210108/9f2ea7be/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image0b65ab.JPG
Type: image/jpeg
Size: 4989 bytes
Desc: image0b65ab.JPG
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210108/9f2ea7be/attachment.jpe>


More information about the cfe-dev mailing list