Board index » cppbuilder » c++ syntax

c++ syntax


2006-05-02 03:34:57 AM
cppbuilder27
I was looking at some code and was wondering what the following does:
+= (ex. context->count[0] += ((UINT4)inputLen << 3)
(UINT4)var (ex. (UINT4)inputLen << 3)
(POINTER)var (ex. (POINTER)input)
&var (ex. &context->buffer[index])
and what is UINT4 when used in declaring a variable(i'm assuing 4 bit
unsigned int but i'm not sure).
Malcolm VanOrder
 
 

Re:c++ syntax

Quote
and what is UINT4 when used in declaring a variable(i'm assuing 4 bit
unsigned int but i'm not sure).
I figured it out it's defined in another copy of the same code. it's
typedefed as an unsigned int)
 

Re:c++ syntax

"Malcolm VanOrder" < XXXX@XXXXX.COM >writes:
Quote
I was looking at some code and was wondering what the following does:

+= (ex. context->count[0] += ((UINT4)inputLen << 3)
+= is a compound assignment operator. The expression a += b assigns a
the result of evaluating a+b.
Quote
(UINT4)var (ex. (UINT4)inputLen << 3)
This is type cast. The expression (T)expr, where T is the name of a
type and expr is an expression (such as a variable name) converts the
value of the expression to the type named by T.
In C++, you are typically better off using a cast operator (often
static_cast) instead, because casts allow programmers to give up some
protection that they otherwise get by the type system; as a
consquence, casts are often where errors are, so it's good to make
them stand out.
Quote
(POINTER)var (ex. (POINTER)input)
Same thing as above.
Quote
&var (ex. &context->buffer[index])
The expression &var takes the address of var.
Quote
and what is UINT4 when used in declaring a variable(i'm assuing 4
bit unsigned int but i'm not sure).
UINT4 is not an official name of a type. It means whatever the
programs defines it to mean.
Please do yourself a favor and buy a good text book. The reviews at
www.accu.org/ will be of help.
 

{smallsort}

Re:c++ syntax

Quote
+= is a compound assignment operator. The expression a += b assigns a
the result of evaluating a+b.
I remember reading that but, had forgoten about it.
Quote
>&var (ex. &context->buffer[index])

The expression &var takes the address of var.
so is &var at all like *var?
I don't buy anything. I use my dads software to write programs and I get
books from the library. What I can't find there I search the internet for
and if I can't find it there I ask around on newsgroups and forums.
 

Re:c++ syntax

"Malcolm VanOrder" < XXXX@XXXXX.COM >wrote in message
Quote
>The expression &var takes the address of var.

so is &var at all like *var?

Not really.
&var is the address of something.
*var would only make sense if var already holds the address of
something (var is a pointer). Then *var means "the thing that var
points to".
e.g.:
int foo(0); // declare an int named foo and give it the value 0
int *var; // this declares your intent to store the address of an int
in var
...
var = &foo; // var now holds the address of the integer named foo
*var = 1; // assigns 1 to foo
It gets a little more confusing because C++ also lets you declare a
reference to something:
int foo(0); // declare an int named foo and give it the value 0
int &var (foo); // the reference var refers to foo (another name for
foo)
...
var = 1; // same as before, assigns 1 to foo
It's like writing *var when var was declared a pointer.
The difference is that with a pointer variable, you can wait and
assign an address to it later. A reference declaration always has to
refer to something, so you can't write this:
int &var; // declare an uninitialized reference
--
Bruce