spamsink: (Default)
[personal profile] spamsink

#include <algorithm>
struct A { int a; };
struct B { long b; };
struct C { char data[std::max(sizeof(A), sizeof(B))]; }; 


Компилируем: line 4: error: array bound is not an integer constant

Subj.

Я понимаю, почему это происходит, но не понимаю, какого рожна это можно терпеть.

Date: 2012-09-26 01:11 am (UTC)
From: [identity profile] archaicos.livejournal.com
constexpr не хватает?

Date: 2012-09-26 03:59 am (UTC)
From: [identity profile] fatoff.livejournal.com
М... статический if придумали... хотя у тебя нет 11-го... но ведь будет! http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Static-If-I-Had-a-Hammer

Date: 2012-09-26 02:33 pm (UTC)
From: [identity profile] sab123.livejournal.com
contexpr - это новое слово из 2011?

Date: 2012-09-26 01:31 am (UTC)
From: [identity profile] dvv.livejournal.com
Для этого господь дал нам юнионы.

Date: 2012-09-26 01:47 am (UTC)
From: [identity profile] dvv.livejournal.com
Не было у бабы забот.

Date: 2012-09-26 02:44 am (UTC)
From: [identity profile] solomon2.livejournal.com
Переходите на нормальный язык уже! ;)

Date: 2012-09-26 05:29 pm (UTC)
From: [identity profile] lider.livejournal.com
struct A { int a; };
struct B { long b; };
union AB{ struct A a; struct B b;};
struct C { char data[sizeof(AB)]; };
Edited Date: 2012-09-26 05:35 pm (UTC)

Date: 2012-09-26 05:44 pm (UTC)
From: [identity profile] lider.livejournal.com
struct A {
public: A(int zero){ a = zero; }
int a; };
struct B {
protected:
B(long int zero = 0L){ b = zero;}
long b; };
union AB{ struct A a; struct B b;};
struct C { char data[sizeof(AB)]; };

bool compilable = true;

Date: 2012-09-26 06:02 pm (UTC)
From: [identity profile] lider.livejournal.com
можно на тьї, я ж штатский ;)

На моем компилится так как я записал,
на старом будет так:

struct A {public: A(int zero){ a = zero; } int a; };
struct B {protected: B(long int zero = 0L){ b = zero;} long b; };

struct dA { char data[sizeof(A)];};
struct dB { char data[sizeof(B)];};

union AB{ struct dA a; struct dB b;};

struct C { char data[sizeof(AB)]; };

Edited Date: 2012-09-26 06:27 pm (UTC)

Date: 2012-09-26 06:55 pm (UTC)
From: [identity profile] lider.livejournal.com
"А отредактированный длинее, чем char data[sizeof(A) > sizeof(B) ? sizeof(A) : sizeof(B)];"

Колоссально!

Date: 2012-09-27 06:49 pm (UTC)
From: [identity profile] lider.livejournal.com
cc --version
Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)

так что там у кого длиннее? Для интереса полез на онлайн-компилятор - везде одинаковая длина.

Код в студию!

Date: 2012-09-27 07:23 pm (UTC)
From: [identity profile] lider.livejournal.com
таки да колоссально.

http://codepad.org/Knn5Detq

Page generated Mar. 5th, 2026 01:16 pm
Powered by Dreamwidth Studios