473,382 Members | 1,420 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,382 software developers and data experts.

unfamiliar syntax

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
3 1492
-----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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
22
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if...
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
23
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
10
by: KevinGPO | last post by:
I am trying to analyse this piece of C++ code below. It is an example code from qwt.sf.net which is an extension to QT graphics library. I assume line 03 is calling a constructor? I have never...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
4
by: Jeremy Yallop | last post by:
Looking over some code I came across a line like this if isalnum((unsigned char)c) { which was accepted by the compiler without complaint. Should the compiler have issued a diagnostic in this...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
2
by: shk253 | last post by:
Hi all - The following is the code for one of my functions in a program but the compiler is reporting errors. I've also tried declaring the variable temp within the function but the number of errors...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.