By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

unfamiliar syntax

P: n/a
Hi all,

I'm teaching myself C, and I've come upon syntax in a program (Ping)
that I don't understand. For instance, we have

struct sockaddr_in *to = (struct sockaddr_in *) &whereto;

and then

bzero((char *)&whereto, sizeof(struct sockaddr) );

And all throughout we have stars within parenthese like (char *) and
(struct wawa *). What do these mean? It must be something about a
pointer, but I haven't been able to find this anywhere in the books I
have, but then, I'm not quite sure how I would find it even if it's
there. Thx.

Greg

Sep 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
gm********@gmail.com wrote:
Hi all,

I'm teaching myself C, and I've come upon syntax in a program (Ping)
that I don't understand. For instance, we have

struct sockaddr_in *to = (struct sockaddr_in *) &whereto;

and then

bzero((char *)&whereto, sizeof(struct sockaddr) );

And all throughout we have stars within parenthese like (char *) and
(struct wawa *). What do these mean?
These expressions force a type conversion to the type named within the
parentheses.

In your example
struct sockaddr_in *to = (struct sockaddr_in *) &whereto;
whereto is presumably defined as something other than a struct
sockaddr_in.
The (struct sockaddr_in *) coerces &whereto to be interpreted as a
pointer to a struct sockaddr_in.

>It must be something about a
pointer,
In your examples it is. However, in the general case, type coersion can
be used on any type, not just pointers. Such coersion is often
unnecessary, and (as it is dangerous) should be used with caution.
but I haven't been able to find this anywhere in the books I
have, but then, I'm not quite sure how I would find it even if it's
there. Thx.
HTH
- --
Lew Pitcher

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFFE/pdagVFX4UWr64RAm0rAKDV2AyR6E3A2tOBQ6mt3IF/1som7QCeO9Uk
V6RlLaZEVXUyjUlFpUPusr4=
=fhyM
-----END PGP SIGNATURE-----

Sep 22 '06 #2

P: n/a
Thanks very much, I get it now.

Greg

Lew Pitcher wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
gm********@gmail.com wrote:
Hi all,

I'm teaching myself C, and I've come upon syntax in a program (Ping)
that I don't understand. For instance, we have

struct sockaddr_in *to = (struct sockaddr_in *) &whereto;

and then

bzero((char *)&whereto, sizeof(struct sockaddr) );

And all throughout we have stars within parenthese like (char *) and
(struct wawa *). What do these mean?

These expressions force a type conversion to the type named within the
parentheses.

In your example
struct sockaddr_in *to = (struct sockaddr_in *) &whereto;
whereto is presumably defined as something other than a struct
sockaddr_in.
The (struct sockaddr_in *) coerces &whereto to be interpreted as a
pointer to a struct sockaddr_in.

It must be something about a
pointer,

In your examples it is. However, in the general case, type coersion can
be used on any type, not just pointers. Such coersion is often
unnecessary, and (as it is dangerous) should be used with caution.
but I haven't been able to find this anywhere in the books I
have, but then, I'm not quite sure how I would find it even if it's
there. Thx.

HTH
- --
Lew Pitcher

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFFE/pdagVFX4UWr64RAm0rAKDV2AyR6E3A2tOBQ6mt3IF/1som7QCeO9Uk
V6RlLaZEVXUyjUlFpUPusr4=
=fhyM
-----END PGP SIGNATURE-----
Sep 22 '06 #3

P: n/a
gm********@gmail.com wrote:
Thanks very much, I get it now.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
Sep 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.