
Вопрос тут возник по С++.
Что у меня дано:
struct s
{
bool b;
};
void foo (s * p)
{
if (p->b)
{
bar(); // <-- косвенно, очень косвенно меняет p->b
if (p->b)
{
buzz();
}
}
}Необходимо ли указать volatile у s::b?
9 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2007-02-17 23:15 |
| (no subject) |
| Public |
| cpp |
Сегодня нашел у себя забавный косяк, который решился с помощью explicit конструктора. Будет мне новое слово в с++ копилку и опыт не забывать explicit вот в таких вот ситуациях :
struct Parent
{
};
struct Child : public Parent
{
explicit Child(const Parent & c);
};
4 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
Не давно зашел разговор про то, что же считать POD типом. Я даже как то не смог, четко сказать, чего там быть не должно, единственное, о чем вспомнил - отсутствие виртуальных функций.
Вчера полез в стандарт и все что нашел:
9/4 A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator and no user-defined destructor. Similarly, a POD-union is an aggregate union that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no userdefined copy assignment operator and no user-defined destructor. A POD class is a class that is either a POD-struct or a POD-union. Вот тут я нашел следующее: As an example, the C declaration struct Fred x; does not initialize the members of the Fred variable x. To make this same behavior happen in C++, Fred would need to not have any constructors. Similarly to make the C++ version of copying the same as the C version, the C++ Fred must not have overloaded the assignment operator. To make sure the other rules match, the C++ version must not have virtual functions, base classes, non-static members that are private or protected, or a destructor. It can, however, have static data members, static member functions, and non-static non-virtual member functions. Так все таки можно ли в POD-типе иметь конструктор или нет?
6 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
Кстати, да. Тут лежит версия стандарта от 2003 года. И из нее можно копировать ;))
5 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
 |
| 2006-03-06 18:13 |
| (no subject) |
| Public |
| cpp |
|
Вот нашел сегодня такой косяк в билдере или это может я что-то не то делаю ;) Под седьмой студией нормально компилируется.
Код:
enum e_enum
{
e1, e2, e3
};
template <class T>
struct table
{
std::vector<T> tbl;
};
struct table2
{
};
template <e_enum X>
struct entity
{
static table<entity<X> > * tbl_;
//static table2 * tbl_;
};
template <e_enum X>
table<entity<X> > * entity<X>::tbl_ = 0; // косяк тут !
//template <e_enum eee>
//table2 * entity<eee>::tbl_ = 0;
/*
[C++ Error] Unit1.cpp(32): E2356 Type mismatch in redeclaration of 'entity<X>::tbl_'
[C++ Error] Unit1.cpp(27): E2344 Earlier declaration of 'entity<X>::tbl_'
*/
Как бы это исправить еще?
2 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2005-11-09 19:45 |
| cpp :: sizeof(enum) |
| Public |
| Origa - The Best Of 1999 - 02 - Lilika |
| cpp |
enum e_type
{
pt_data
, pt_data_accept
, pt_error
};sizeof(enum) Implementation defined. Легальным ли будет хак (см. ниже) для того, чтобы в C++ Builder 6 и студии 2003 sizeof был одинаковый? enum e_type
{
pt_data
, pt_data_accept
, pt_error
, pt_hack = INT_MAX
};Да, да - сам не хочу юзать BCB, но пока деваться некуда :(
3 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2005-11-08 14:00 |
| что я буду читать |
| Public |
| Origa - The Best Of 1999 - 04 - We Can Hear Your Pulse |
| cpp |
Хехе, сделал себе маленький подарочек: купил книги Саттера "Решение сложных задач на С++" и "Новые сложные задачи на С++".

11 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2005-10-25 19:18 |
| (no subject) |
| Public |
| cpp |
int foo(int & bar)
{
return bar = 1;
}
int main()
{
int bar = 1;
bar = foo(bar);
}
Что здесь преступного? programming cpp
20 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2005-10-04 20:02 |
| (no subject) |
| Public |
| Bubblegum Crisis - Bluew - Mr. Dandy |
| cpp |
По сравнению со студией с++ билдер имеет убогую систему watch'ей. Debug Inspector это вообще отдельный ужас. И редактор там ужасный, скажу по секрету - код для билдера пишу в студии ;)
cpp
3 Comments | Post A Comment | Add to Memories | Tell a Friend | Link
| 2005-09-20 19:16 |
| (no subject) |
| Public |
| cpp |
... код: printf( "%d %d", f( i++ ), f( i++ ) );
И никто того программера не собирается за ворота, а очень даже уважаемый программист в конторе. И другие еще удивлялись, а че это глючит? И знаете какое решение нашли? Эту пременную объявили volatile. Добро пожаловать в реальный мир... тутЯ поражаюсь этим людям :((
1 Comment | Post A Comment | Add to Memories | Tell a Friend | Link
|