Różnica pomiędzy int / int_fast#_t / int_least#_t?

0

Witam, próbuje zrozumieć różnicę pomiędzy typami danych jakimi są int / int_fast#_t / int_least#_t. Jak najprościej to zrozumieć, najlepiej na podstawie jakiegoś przykładu? Z góry dziękuje za pomoc.

0

A Szukales po internecie?

https://stackoverflow.com/questions/5254051/the-difference-of-int8-t-int-least8-t-and-int-fast8-t

From the spec section 7.8.1.1 Exact-width integer types, paragraph 1:

The typedef name intN_t designates a signed integer type with width N , no padding bits, and a two’s complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.

And from: 7.18.1.2 Minimum-width integer types, paragraph 1:

The typedef name int_leastN_t designates a signed integer type with a width of at least N, such that no signed integer type with lesser size has at least the specified width. Thus, int_least32_t denotes a signed integer type with a width of at least 32 bits.

And finally from 7.18.1.3 Fastest minimum-width integer types, paragraph 2:

The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N.
0

Tak znalazłem tą odpowiedź w internecie i problem polega na tym że nie potrafię tego do końca zrozumieć, np kiedy powinnyśmy używać "fast" i "least" a kiedy po prostu int. Rozumiem co jest tutaj napisane ale za grosz nie chce mi to wejść do głowy tak jak powinno, dlatego chciałem zapytać o jakiś prosty przykład. O ile to możliwe.

2

W zaokrągleniu 100% programistów nie potrzebuje tych typów. Używaj int lub intX_t jeśli potrzebujesz konkretnej wielkości. Ewentualnie ich unsigned odpowiedników.

int_leastX_t - gdy potrzebujesz typu o danym rozmiarze, ale akceptujesz większy, np. jeśli taki nie jest dostępny na danej platformie

int_fastX_t - gdy potrzebujesz typu o rozmiarze X, ale przede wszystkim liczy się prędkość obliczeń. Np. na x86 i x86_64 obliczenia na 8-bitowych integerach mogą być wolniejsze, ponieważ procesor musi konwertować wartości z/do wielkości rejestrów.

1 użytkowników online, w tym zalogowanych: 0, gości: 1