powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / AnsiString и unsigned char*
4 сообщений из 29, страница 2 из 2
AnsiString и unsigned char*
    #33987883
Akh
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Карабас Барабас AkhДык это уже не С?как это не С ? я другими языками не владею :)

Я не встречал такого в учебниках :(
...
Рейтинг: 0 / 0
AnsiString и unsigned char*
    #33987942
Карабас Барабас
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
AkhЯ не встречал такого в учебниках :(
полез в стандарт:
ANSI/ISO C++ Professional Programmer's HandbookInitializing Local Automatic Structs and Arrays

One way to initialize automatic POD objects is by calling memset() or a similar initialization function. However, there is a much simpler way to do it -- without calling a function, as you can see in the following example:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
struct  Person
{
  long ID;
  int bankAccount;
  bool retired;
};
int main()
{
  Person person ={ 0 }; //ensures that all members of
                      //person are initialized to binary zeros
  return  0 ;
}

This technique is applicable to every POD struct. It relies on the fact that the first member is a fundamental data type. The initializer zero is automatically cast to the appropriate fundamental type. It is guaranteed that whenever the initialization list contains fewer initializers than the number of members, the rest of the members are initialized to binary zeros as well. Note that even if the definition of Person changes -- additional members are added to it or the members' ordering is swapped -- all its members are still initialized. The same initialization technique is also applicable to local automatic arrays of fundamental types as well as to arrays of POD objects :

[src c++]void f()
{
char name[100] = {0}; //all array elements are initialized to '\0'
float farr[100] = {0}; //all array elements are initialized to 0.0
int iarr[100] = {0}; //all array elements are initialized to 0
void *pvarr[100] = {0};//array of void * all elements are initialized to NULL
//...use the arrays
}[src]
Posted via ActualForum NNTP Server 1.3
...
Рейтинг: 0 / 0
AnsiString и unsigned char*
    #33987947
Akh
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Карабас Барабас

Супер! Я даже и не мечтал. :)
...
Рейтинг: 0 / 0
AnsiString и unsigned char*
    #33987949
Карабас Барабас
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
вернее вот так:
ANSI/ISO C++ Professional Programmer's HandbookInitializing Local Automatic Structs and Arrays

One way to initialize automatic POD objects is by calling memset() or a similar initialization function. However, there is a much simpler way to do it -- without calling a function, as you can see in the following example:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
struct  Person
{
  long ID;
  int bankAccount;
  bool retired;
};
int main()
{
  Person person ={ 0 }; //ensures that all members of
                      //person are initialized to binary zeros
  return  0 ;
}

This technique is applicable to every POD struct. It relies on the fact that the first member is a fundamental data type. The initializer zero is automatically cast to the appropriate fundamental type. It is guaranteed that whenever the initialization list contains fewer initializers than the number of members, the rest of the members are initialized to binary zeros as well. Note that even if the definition of Person changes -- additional members are added to it or the members' ordering is swapped -- all its members are still initialized. The same initialization technique is also applicable to local automatic arrays of fundamental types as well as to arrays of POD objects :

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
void f()
{
  char  name[ 100 ] = { 0 }; //all array elements are initialized to '\0'
  float farr[ 100 ] = { 0 }; //all array elements are initialized to 0.0
  int  iarr[ 100 ] = { 0 };  //all array elements are initialized to 0
  void *pvarr[ 100 ] = { 0 };//array of void * all elements are initialized to NULL
  //...use the arrays
}

Posted via ActualForum NNTP Server 1.3
...
Рейтинг: 0 / 0
4 сообщений из 29, страница 2 из 2
Форумы / C++ [игнор отключен] [закрыт для гостей] / AnsiString и unsigned char*
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]