Skip to content

Instantly share code, notes, and snippets.

@StephanDollberg
Last active October 27, 2019 17:33
Show Gist options
  • Save StephanDollberg/187c067ce3b223bd0b0b847f4191337f to your computer and use it in GitHub Desktop.
Save StephanDollberg/187c067ce3b223bd0b0b847f4191337f to your computer and use it in GitHub Desktop.
lambda size
#include <cstdio>
int main() {
int x = 23;
int y = 45;
auto l1 = [] () {
std::printf("l1\n");
};
auto l2 = [&x] () {
std::printf("l2 %d\n", x);
};
auto l3 = [&y] () {
std::printf("l3 %d\n", y);
};
auto l4 = [&] () {
std::printf("l4 %d\n", y);
};
auto l5 = [&] () {
if (false)
{
std::printf("l5 %d\n", y);
}
else
{
std::printf("l5\n");
}
};
std::printf("l1 size: %lu\n", sizeof(l1));
std::printf("l2 size: %lu\n", sizeof(l3));
std::printf("l3 size: %lu\n", sizeof(l3));
std::printf("l4 size: %lu\n", sizeof(l4));
std::printf("l5 size: %lu\n", sizeof(l5));
l1();
l2();
l3();
l4();
l5();
return 0;
}
/*
l1 size: 1
l2 size: 8
l3 size: 8
l4 size: 8
l5 size: 8
l1
l2 23
l3 45
l4 45
l5
*/
@StephanDollberg
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment