AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is small like C++ (https://forums.alliedmods.net/showthread.php?t=3853)

Meatwad 07-16-2004 20:27

Is small like C++
 
I recentley learned C++, and I am looking at some of Gir's old plugins. It seems that, Small is a rip-off, of C++.

sanaell 07-16-2004 20:49

Re: Is small like C++
 
Quote:

Originally Posted by Meatwad
I recentley learned C++, and I am looking at some of Gir's old plugins. It seems that, Small is a rip-off, of C++.

rip off ?
you can t compile to execute in standalone version !

not a rip off
tssss
Basic is a rip of LOGO ( lol )

BAILOPAN 07-16-2004 21:53

Almost all languages these days follow a C style syntax, noted by Allman-style block coding, semicolons for line termination, and cell/array based data types (C-Style strings).

Small was originally called "SmallC", it's meant to be a tiny, compact version of C which can run on an embedded machine. While certainly not the best of scripting languages or machines, it IS compact and easy to learn, and the fact that it doesn't compile to stand alone machine code (instead, to bytecode) makes it cross-platform.

Ingram 07-17-2004 05:54

Bailopan, u seem to know a lot about this kinda stuff. I was always wondering, why ==? Didn't whats his name say nothing can be more equal than =. lol

sanaell 07-17-2004 06:55

Quote:

Originally Posted by JJkiller
Bailopan, u seem to know a lot about this kinda stuff. I was always wondering, why ==? Didn't whats his name say nothing can be more equal than =. lol

== is a comparator ( often double sign like &&, ||, <<, >> etc...)

= is just to assign a value to a variable like a=0
(you set a to 0)
so

a=1
b=2
c=a+b
(c = 3)
if you made that now
if (a == b)
a = b + 1
else if b < a
a = b - 1
etc....

- the << and >> is a byte (i believe) utilisation
i use often == (but remind)

a == 1 can be if(a)
and a == 0 can be if(!a)

BAILOPAN 07-17-2004 07:38

It's a bit more complicated than that...

= is the unary "assignment" operator
== is the binary "equal" operator
a = b will set b equal to a, and then return a
a == b will check if a is equal to b (returning 1 or 0)

and in PHP, it gets weirder, there is
a === b which checks if two things have the same data type also

if (a = b) will return whether b is true
if (a == b) will return whether a is equal to b

PM 07-17-2004 10:50

I have some things to add :D :
Code:
if (a)
means
Code:
if (a != 0)

and

Code:
if (!a)
means
Code:
if (a == 0)

When we are talking about operators:
All stuff about bit setting / shifting / checking / ...

For ilustration i will only use 8 bits:
Code:
// .....   name  value     bit value #define BIT_1 1        // 00000001 #define BIT_2 2        // 00000010 #define BIT_3 4        // 00000100 #define BIT_4 8        // 00001000 #define BIT_5 16       // 00010000 #define BIT_6 32       // 00100000 #define BIT_7 64       // 01000000 #define BIT_8 128      // 10000000
Then you can use the LOGICAL OR ( '|' ) and LOGICAL AND ( '&' ).

LOGICAL OR:
Basically loops through all bits of two integers and creates a new integer in this way:
Code:
Integer1 01001010 Integer2 11000100 Result   11001110
So the bit in result will be set to 1 if the same bit in Integer1 _OR_ in Integer2 is 1

LOGICAL AND:
Basically loops through all bits of two integers and creates a new integer in this way:
Code:
Integer1 01001010 Integer2 11000100 Result   01000100
This will only set a bit to 1 when the same bit is 1 in Integer1 _AND_ Integer2.

BUT:
x && y
does basically
(x!=0) & (y != 0)
( same with || )

When u write
Code:
x |= y
it could be translated (=it does the same thing) to this:
Code:
x = x | y

You can do the same with '&' ( -> 'x &= y' )

Now you can use these operators to make a "bit sum".
Code:
new a = 0;   // 00000000 a |= BIT_3   // 00000100 // means: //    a = a | BIT_3 // -> a = 00000000 | 00000100 = 00000100 a |= BIT_7 // means: //    a = a | BIT_3 // -> a = 00000100 | 01000000 = 01000100

Now we have an 8-byte integer a in which the third and the seventh bits are set.

We want to check which bits are set. So we will do:
Code:
// Check // BIT_3 if ((a & BIT_3) != 0) {      // BIT_3 is set }
it works like this:
Code:
if ((a & BIT_3) != 0) // if ((01000100 & 00000100) != 0) // We know that 01000100 & 00000100 = 00000100 // so it isn't 0 when BIT_3 is set.
Now let's check BIT_5
Code:
// Check // BIT_5 if ((a & BIT_5) != 0) {     // BIT_5 is set }
=
Code:
if ((a & BIT_5) != 0) // if ((01000100 & 00010000) != 0) // We know that 01000100 & 00010000 = 00000000 // so it isn 0 when BIT_5 is not set.

bit shift left:
Code:
10001001  <<  1 = 00010010
And
Code:
10001001  <<  2 = 00100100
could be written as
Code:
(10001001  <<  1) << 1 = 00100100

bit shift right: The same thing, other direction :)

So u can use 1 << x to generate values like 1, 2, 4, 8, 16, 32, ...

BAILOPAN 07-17-2004 11:12

wow, very nice write-up PM :)

Dygear 07-17-2004 13:29

WOW ... WOW ......... WOW. :shock:

Meatwad 07-17-2004 15:11

so.... what is the difference?


All times are GMT -4. The time now is 14:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.