Игры с литералами
От: Шахтер Интернет  
Дата: 12.09.20 10:44
Оценка:
FYI

/* main.cpp */

#include <CCore/inc/Print.h>

using namespace CCore;

/* test() */

void test(int a)
 {
  Printf(Con,"int #.h;\n",a);
 }

void test(unsigned a)
 {
  Printf(Con,"unsigned #.h;\n",a);
 }

void test(UIntType auto a)
 {
  Printf(Con,"unsigned ??? #.h;\n",a);
 }

void test(SIntType auto a)
 {
  Printf(Con,"signed ??? #.h;\n",a);
 }

/* main() */

int main() 
 {
  test(0x7FFF'FFFF);  
  test(0x7FFF'FFFFu);  
  test(0x8000'0000);  
  test(0xFFFF'FFFF);

  test(0x1'0000'0000);
  test(0x7FFF'FFFF'FFFF'FFFF);
  test(0x7FFF'FFFF'FFFF'FFFFu);
  test(0x8000'0000'0000'0000);

  test(0x1'0000'0000'0000'0000);
  test(0x1'0000'0000'0000'0000u);

  test(0x1'1000'0000'0000'0000);
  test(0x1'1000'0000'0000'0000u);

  return 0;
 }


печатает

D:\active\home\C++\CCore-try\blank>make run                                            
CC main.cpp                                                                            
CAT                                                                                    
CC main.cpp                                                                            
main.cpp:43:8: warning: integer constant is too large for its type                     
   43 |   test(0x1'0000'0000'0000'0000);                                               
      |        ^~~~~~~~~~~~~~~~~~~~~~~                                                 
main.cpp:44:8: warning: integer constant is too large for its type                     
   44 |   test(0x1'0000'0000'0000'0000u);                                              
      |        ^~~~~~~~~~~~~~~~~~~~~~~~                                                
main.cpp:46:8: warning: integer constant is too large for its type                     
   46 |   test(0x1'1000'0000'0000'0000);                                               
      |        ^~~~~~~~~~~~~~~~~~~~~~~                                                 
main.cpp:47:8: warning: integer constant is too large for its type                     
   47 |   test(0x1'1000'0000'0000'0000u);                                              
      |        ^~~~~~~~~~~~~~~~~~~~~~~~                                                
LD test.exe                                                                            
./test.exe                                                                             
int 7FFFFFFFh                                                                          
unsigned 7FFFFFFFh                                                                     
unsigned 80000000h                                                                     
unsigned FFFFFFFFh                                                                     
signed ??? 100000000h                                                                  
signed ??? 7FFFFFFFFFFFFFFFh                                                           
unsigned ??? 7FFFFFFFFFFFFFFFh                                                         
unsigned ??? 8000000000000000h                                                         
int 0h                                                                                 
unsigned 0h                                                                            
signed ??? 1000000000000000h                                                           
unsigned ??? 1000000000000000h                                                         
                                                                                       
D:\active\home\C++\CCore-try\blank>
В XXI век с CCore.
Копай Нео, копай -- летать научишься. © Matrix. Парадоксы
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.