+ 2
Where and when do we use the keywords 'asm' & 'short' in c++?
please give me the example where we use these keywords -» asm & short in c++?
4 ответов
+ 3
Short can be used any place you might use int, when the integer range is within 2 bytes or -32768 to 32767.
Asm allows you to code Assembly instructions.
asm("ret"); // Return from the function
http://en.cppreference.com/w/cpp/language/asm
+ 3
Is asm part of the standard or is it a compiler feature?
+ 3
Officially, it is conditionally-supported and implementation defined. GCC supports it so it works in SoloLearn playground. There are a bunch of codes I've seen here. As to running with other compilers, there is no guarantee.
+ 1
The 'asm' keyword is for inline assembly code, I believe, and 'short' is for integral type variables. It is "an integral type that is larger than or equal to the size of type char, and shorter than or equal to the size of type int" (https://msdn.microsoft.com/en-us/library/cc953fe1.aspx). I don't know of any examples for asm, as I've never written in assembly; however, using short is just as easy as using long. Say I have a player, and I use a variable called 'level' that keeps their level. I don't ever need the level to go very high. Maybe 500 is the highest it will go, so...
short int level = 1;
//the limit of short int is +/- 32,767