473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What does this mean ?

Hi all
How to explain the *s below.

char **addrs;
...
printf("%s\n",inet_ntoa(*(struct in_addr *)*addrs));
The define of inet_ntoa() is : char *inet_ntoa(struct in_addr in);

Thanks.

Mar 6 '06 #1
2 2027
Roka wrote:
Hi all
How to explain the *s below.

char **addrs;
...
printf("%s\n",inet_ntoa(*(struct in_addr *)*addrs));
The define of inet_ntoa() is : char *inet_ntoa(struct in_addr in);


I guess what was tried was:

`addrs` is a pointer to a pointer to `char`
`*addrs` gets you the pointer to `char`
`(struct in_addr *)*addrs` casts that to a pointer to `struct in_addr`
that is then dereferenced to be passed to `inet_ntoa()`

So, it seems that wherever the pointer `addrs` points, is supposed to
contain a series of `char`s, which are supposed to be able to be
interpreted as `struct in_addr`.

Quite abominable, IMHO...

--
BR, Vladimir

Democracy is the theory that the common people know what they want, and
deserve to get it good and hard.
-- H.L. Mencken, "Little Book in C major", 1916

Mar 6 '06 #2
On Mon, 6 Mar 2006 07:03:46 +0000 (UTC), "Vladimir S. Oka"
<no****@btopenworld.com> wrote:
Roka wrote:
Hi all
How to explain the *s below.

char **addrs;
...
printf("%s\n",inet_ntoa(*(struct in_addr *)*addrs));
The define of inet_ntoa() is : char *inet_ntoa(struct in_addr in);
I guess what was tried was:

`addrs` is a pointer to a pointer to `char`
`*addrs` gets you the pointer to `char`
`(struct in_addr *)*addrs` casts that to a pointer to `struct in_addr`
that is then dereferenced to be passed to `inet_ntoa()`

So, it seems that wherever the pointer `addrs` points, is supposed to
contain a series of `char`s, which are supposed to be able to be
interpreted as `struct in_addr`.

Right.
Quite abominable, IMHO...


Poor for standard C, yes. <OT> However, this is the type returned by
the (BSD-to-SUS/POSIX) gethost* functions for the list of network
addresses, since the API was intended to support a whole range of
protocol stacks, of which only 2 survive and only 1 (IP) matters.

The whole BSD API was designed to use a series of structures that are
in fact laid out to be compatible, but are not declared that way to
the C compiler to allow separate development (and extension), and thus
is one of the few places well-written (Unixoid) C _needs_ casts.
In retrospect it is not clear whether this design was really worth it,
but it's far too late to change now. </>

- David.Thompson1 at worldnet.att.net
Mar 20 '06 #3

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
1
by: Frank Rizzo | last post by:
Some of the classes in the framework are marked as thread-safe in the documentation. In particular the docs say the following: "Any public static (*Shared* in Visual Basic) members of this type...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: JoeC | last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; What does this mean? I have seen v=&var->member.thing; but what does it mean when you...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.