473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

(UINT16 *)&apple

Dear All,
I knew "&apple" could get the address of apple variable, about why we use a
(UINT16 *) command before "&apple" ?

What is this function for?
Thank you very much for your help.

Best regards,

Boki.
Jul 22 '05 #1
2 2154
> I knew "&apple" could get the address of apple variable, about why
we use a
(UINT16 *) command before "&apple" ?

What is this function for?


It's a 'cast 'operator'. If Apple e.g. is of the type 'INT16', but
your function requires a UINT16*, you must cast it to that type. Be
sure you know what you do, since this:

double a=5;

*((int*)&a) = 5;
printf("%d", a);

will result in a funny number. The memory used for 'a' will be cast so
the compiler thinks it really _is_ an int that you are pointing to.
Assinging the first 4 bytes of a double with 0x00000005 will result in
anything else than '5.0'.
-Gernot
Jul 22 '05 #2
Wow, it is really useful.

Thank you very much for your help.

Best regards,

Boki.

"Gernot Frisch" <Me@Privacy.net> wrote in message news:<2q*************@uni-berlin.de>...
I knew "&apple" could get the address of apple variable, about why
we use a
(UINT16 *) command before "&apple" ?

What is this function for?


It's a 'cast 'operator'. If Apple e.g. is of the type 'INT16', but
your function requires a UINT16*, you must cast it to that type. Be
sure you know what you do, since this:

double a=5;

*((int*)&a) = 5;
printf("%d", a);

will result in a funny number. The memory used for 'a' will be cast so
the compiler thinks it really _is_ an int that you are pointing to.
Assinging the first 4 bytes of a double with 0x00000005 will result in
anything else than '5.0'.
-Gernot

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: rwc | last post by:
I've got the following array I want to pass to smarty: a apple a artichoke b banana I want the output to look like: a 2 items apple articoke
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
9
by: Merrill & Michele | last post by:
What follows is an adaptation of the second program in K&R §5.10. The changes are to elucidate (validate) the difference (sameness) of char * and char**. I cannot for the life of me understand...
6
by: barcaroller | last post by:
I'm looking for a hash function (in C) that will convert a string of arbitrary length (but less than 1024 chars) to a reasonably-unique 16-bit short integer. Can anyone point me to such a hash...
5
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------ #include <iostream> void g(char&){}; void h(const char&) {}; int main() { char c;
2
by: SuperHeroGeek | last post by:
Hello.. I work for a newspaper that has several newsstand listings for all different cities and states. Currently, they are uploaded manually by copying and pasting. I would like to make the whole...
1
by: DILA | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the...
3
by: homec | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the ...
41
by: Gio | last post by:
I'm reading the K&R book and doing the exercises. Currently, I'm working on Exercise 1-3. Here's what I have: #include <stdio.h> main()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.