Toon posts:

[c] implicit typecasting rules (advanced)

Pagina: 1
Acties:

Verwijderd

Topicstarter
.

[ Voor 99% gewijzigd door Verwijderd op 01-11-2023 01:46 ]


  • whoami
  • Registratie: December 2000
  • Laatst online: 00:54
Mag ik je even wijzen op het bestaan van [ code ] tags ?

https://fgheysels.github.io/


Verwijderd

Topicstarter
.

[ Voor 100% gewijzigd door Verwijderd op 01-11-2023 01:46 ]


Verwijderd

Zoek in je compiler doc of op het net eens naar "arithmetic conversions", "integral conversions" en/of "integral promotions". Als je compiler volgens de C/C++ standaard werkt, dan zal je daar het antwoord vinden.

Een alternatief is zelf een aantal varianten testen, en daaruit je eigen conclusie(s) trekken.

Verwijderd

Topicstarter
.

[ Voor 99% gewijzigd door Verwijderd op 01-11-2023 01:46 ]


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 23:31

.oisyn

Moderator Devschuur®

Demotivational Speaker

2.13.1/2
The type of an integer literal depends on its form, value, and suffix. If it is decimal and has no suffix, it has the first of these types in which its value can be represented: int, long int; if the value cannot be represented as a long int, the behavior is undefined. If it is octal or hexadecimal and has no suffix, it has the first of these types in which its value can be represented: int, unsigned int, long int, unsigned long int. If it is suffixed by u or U, its type is the first of these types in which its value can be represented: unsigned int, unsigned long int. If it is suffixed by l or L, its type is the first of these types in which its value can be represented: long int, unsigned long int. If it is suffixed by ul,
lu, uL, Lu, Ul, lU, UL, or LU, its type is unsigned long int.
4.5/1
An rvalue of type char, signed char, unsigned char, short int, or unsigned short
int can be converted to an rvalue of type int if int can represent all the values of the source type; otherwise, the source rvalue can be converted to an rvalue of type unsigned int.
You do the math ;)
.edit: oeps, dit komt uit de C++ standaard trouwens, jouw topic gaat over C zie ik nu. De regels zijn overigens niet heel erg anders, het verschil is vziw dat C99 nog een long long en unsigned long long kent.


Waarom is dit trouwens "advanced"? Ik vind het vrij triviaal eerlijk gezegd :)

[ Voor 26% gewijzigd door .oisyn op 11-05-2007 12:09 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • farlane
  • Registratie: Maart 2000
  • Laatst online: 30-11 00:17
Vind je (advanced) wel grappig eigenlijk.

[edit]
:P

[ Voor 15% gewijzigd door farlane op 11-05-2007 12:07 ]

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.

Pagina: 1