Tuesday, August 30, 2016

Digest for comp.lang.c++@googlegroups.com - 25 updates in 3 topics

Jerry Stuckle <jstucklex@attglobal.net>: Aug 30 08:47AM -0400

On 8/30/2016 8:01 AM, R.Wieser wrote:
 
> Any other ideas ?
 
> Regards,
> Rudy Wieser
 
Look at his update again. He isn't using the address of the first
member - he isn't referencing any member of the struct. You can take
the address of it with & and dereference it with *. For instance:
 
struct hostent server; // the actual structure
 
struct hostent* pserver = &server; // A pointer to the structure
 
At this level, it's really no different than other variables, i.e.
 
int i; // an int
int *ip = &i; // A pointer to an int
 
And you can use them just like other pointers, i.e.
 
void f(struct hostent * ps);
 
f(&server); // Use the address of the structure
f(pserver); // Use a pointer to the structure
 
Does this help?
 
And I agree with the others - you really need to find a good basic book
on C++ (or here, even C). It will help you much more than trying to
fumble your way through.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Aug 30 01:59PM +0100

On Tue, 30 Aug 2016 11:33:23 +0200
 
> Odd: several replies, but none that actually told me how its done.
> Is it some deep-dark secret that only masters of the trade are
> allowed to know ?
 
You have been told the answer (see the response of 29 August at
19:16:59 UTC). 'server', as in:
 
struct hostent *server;
 
is declared as a pointer and can be passed as a pointer. It _is_ a
pointer. You only need to dereference it if you want to obtain the
structure's members. There is no secret here. It is the most basic C.
 
You really do need to get a decent textbook on the C language. (Or
the C++ language if that is what you want to learn.)
 
> not appreciate further hints in the same direction though!)
 
> Do I really need to waste hours googeling hoping I will stumble over
> the (most likely rather simple) answer ?
 
Don't google. When learning a language get a textbook to learn the
basics.
 
Part of the confusion may be that when you said you were "a novice in
regard to using C++ (GCC) *and* using linux" people thought that it was
the specific gcc and linux issues you were unfamiliar with, not the
basics of C and C++ itself. You gave the impression that you had
done some windows programming.
 
The other difficulty is that you have an attitude problem which is
considerably larger than your state of knowledge; this is going to get
you into trouble, both in your code and in your interactions on this
news group.
 
Chris
"R.Wieser" <address@not.available>: Aug 30 03:14PM +0200

Paavo,
 
> I express my opinions, you express yours.
 
Nope. You use your "opinions" as an excuse not to post anything in regard
to an answer to the problem as I posted it. "Go away. Go learn for
yourself. If you do not you will never discover what its all about".
Really ? *Thats* how you help people ? In that case, I wonder what you
would do if you would *not* be willing to help ...
 
> Yes, that was concrete enough, thank you.
 
Good.
 
> 2) foobar(reinterpret_cast<unsigned char*>(server2));
 
Why are you writing it like that, when my posted code uses a different
make-up (syntax?) *AND* I've indicated I'm a beginner ?
 
But, lets assume you ment:
 
foobar( (unsigned char*) server2 );
 
Than you're mistaken (adding brackets around "server2" does not help
either).
 
Oh, it *compiles* well enough, but the argument in the foobar function will
than be pointing at the the value stored into that "server2" variable, not
the data in the "hostent" structure.
 
Also explain to me how currently
 
foobar( (unsigned char*) server2-> h_addr );
 
works for me, but I than can just remove the "->h_addr" part and get the
same (compile-time!) result ...
 
> A proper code sample is preferably a complete source
> file including all the #includes as well as int main().
 
Forget it. The only thing it would lead to is that you (and others like
you) would making suggestions about *everything* in there, but not the
problem. Heck, even now you have troubles with concentrating yourself on
the problem.
 
Over the years I've posted enough questions (few, but enough) to have
encountered the above many times. Shucks, why do you think I named the
function "foobar" instead of its actual name ? Thats because what it, and
the rest of the code does has got *nothing* to do with the *compile-time*
problem.
 
But, if you are amadant about only being able to glean the problem (and its
answer) from such full code I could waste some time to gut everything
irrelevant outof my current code (while ofcourse still causing the
compile-time error mind you). Apart from the includes for the standard IO,
the structure, the gethostbyname function, a minimal "main" declaration and
an as minimal "foobar" one (being fully gutted) you would see nothing more
than what I already posted.
 
By the way: have you already tried to put those three lines of code I posted
in my initial message into some test program and seen if you could get it to
compile ? Why not ? I think it would probably have been quite the
eye-opener for you.
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Paavo Helde <myfirstname@osa.pri.ee> schreef in berichtnieuws
M6idnSfk5aQA6VjKnZ2dnUU78dvNnZ2d@giganews.com...
 
> >> I'm just saying that it is not productive to learn language
> >> basics from a newsgroup, it's too tedious and chaotic.
 
> > Please, let *me* be the judge of that. This is a tiny bit of
knowledge,
> > which, if solved, allows me to progress quite a bit.
 
> Why are not judging here anything, I express my opinions, you express
yours.
 
> > 2) struct hostent *server2;
 
> > For *both* of the above I want to give a pointer to the actual hostent
> > structure to a function called "foobar", which expects the argument to
be of
> using it in the same meaning.)
 
> >> and preferably with a real code sample, not a vague description ...
 
> > Thats what I posted and am using in my code. I'm sorry, but I have no
idea
Paavo Helde <myfirstname@osa.pri.ee>: Aug 30 04:22PM +0300

On 30.08.2016 16:14, R.Wieser wrote:
> yourself. If you do not you will never discover what its all about".
> Really ? *Thats* how you help people ? In that case, I wonder what you
> would do if you would *not* be willing to help ...
 
(plonk)
"R.Wieser" <address@not.available>: Aug 30 03:28PM +0200

Scott,
 
> The man pages are your friend.
 
:-) I was, just as under Windows, trying to go the opposite way -- from
function to documentation -- (Windows does not really have any decent "man"
page support), but yes, "man" seems to work rather well under Linux.
 
And thanks for the info-selection methods too.
 
Regards,
Rudy Wieser
 
 
-- Origional mesage:
Scott Lurndal <scott@slp53.sl.home> schreef in berichtnieuws
Gafxz.1214$LR.855@fx17.iad...
> >> to include stdio.h, use
 
> >> #include <stdio.h>
 
> >Thats exactly the problem. How do I know that I need to include stdio.h
and
> ...
 
> $ man 3 printf | head -20
> PRINTF(3) Linux Programmer's Manual
PRINTF(3)
 
> NAME
> printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf,
vsnprintf - formatted output conversion
"R.Wieser" <address@not.available>: Aug 30 03:22PM +0200

Scott,
 
> $ nm -D /usr/lib64/libzip.so.2 | grep " T " |more
 
Looks like its very usable, thanks. :-)
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Scott Lurndal <scott@slp53.sl.home> schreef in berichtnieuws
s5fxz.1213$LR.467@fx17.iad...
 
> >As someone wo has spend quite some time on Windows I'm rather accustomed
> >being able to pick a DLL and look inside it to see which functions it
> >exposes that I can use (yeah, I still have to generate a library from it
and
"R.Wieser" <address@not.available>: Aug 30 03:30PM +0200

Scott,
 
 
> $ man 3 fprintf
 
> Section 1 is commands, 2 is system calls, 3 is library functions,
> 4 is device special files, etc.
 
Thanks again. Thats rather usefull (to make an understatement).
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Scott Lurndal <scott@slp53.sl.home> schreef in berichtnieuws
Cdfxz.1215$LR.777@fx17.iad...
 
> >:-\ I had not thought of that.
> >...
 
> >Just tested it, and I had ofcourse (among a few others) to choose a
function
> >which clashes with a console command : write. :-( :-) Any idea what to
do
> 5 File formats and conventions eg /etc/passwd
> 6 Games
> 7 Miscellaneous (including macro packages and conventions), e.g.
man(7), groff(7)
Ben Bacarisse <ben.usenet@bsb.me.uk>: Aug 30 02:34PM +0100


> and
 
> struct hostent *server;
 
> I regard your above statement true for the first, not the latter.
 
No, the first is a variable (C and C++ call it an object) that holds the
structure. The second is an object that holds the address of a struct.
 
> I can tell for the latter "server" is the addres of the variable which holds
> the address to the "hostent" structure (hence the need for
> dereferencing).
 
If you just want the address of the hostent strict you just write server
because that variable already holds the address you want. But the code
you showed suggested a different intention:
 
foobar( (unsigned char*) server->h_addr, ... )
 
This suggest you might want to pass the address of the first member of
the list of discovered host addresses: h_addr is a legacy macro that
expands to h_addr_list[0]. If that's what you want, then you've got the
right code. You don't even need the cast if your function can take a
char * argument.
 
But, to repeat, if you just want the address of the whole hostent
struct, you already have it in server.
 
<snip>
--
Ben.
"R.Wieser" <address@not.available>: Aug 30 03:43PM +0200

Jerry,
 
> Does this help?
 
I'm sorry, no. I read the same, and thought I understood.
 
You seem to say that what he wrote works, while the compiler on my machine
still throws an compile-time error.
 
I can see that "server->h_addr" and "*server" *should* return the same
address. The problem is that I can't get the latter to be accepted (and, as
I'm a beginner, assumed I did something wrong), and I have *no* idea why.
 
Do you ?
 
Regards,
Rudy Wieser
 
 
Jerry Stuckle <jstucklex@attglobal.net> schreef in berichtnieuws
nq3v9u$sm2$1@jstuckle.eternal-september.org...
 
> >> For dereferencing you need to type '*server' (or 'server->' if you
> >> want access particular member of it).
 
> > In my first post I indicated I used the latter using the first member of
the
> > structure, but I consider that to be a hack. I also indicated that I
tried
"R.Wieser" <address@not.available>: Aug 30 03:51PM +0200

Scott,
 
> >Odd: several replies, but none that actually told me how its done. Is
it
> >some deep-dark secret that only masters of the trade are allowed to know
?
 
> Pointers are the most basic of concepts in C, and C++.
 
I should have added the "</sarcasm>" tag, but felt like I would be overdoing
it.
 
> Casting your 'server' variable to an unsigned char pointer
> is incorrect in either language.
 
Seems to be untrue. The compiler accepts "(unsigned char*) server" without
even a warning. Using that result does not seem to cause any problems
either.
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Scott Lurndal <scott@slp53.sl.home> schreef in berichtnieuws
Fgfxz.1216$LR.419@fx17.iad...
 
> >> In short: How do I dereference that "server" variable so
> >> the function receives a pointer to the structure ?
 
> >Odd: several replies, but none that actually told me how its done. Is
it
> >some deep-dark secret that only masters of the trade are allowed to know
?
 
> Pointers are the most basic of concepts in C, and C++.
 
> >And for some of you guys here: don't try to second-guess what I'm after.
> >I'm in the habit of trying to ask my questions as exact as I can, needing
it
> >to have *it* answered. (that does not mean that I do not appreciate
further
 
> >Do I really need to waste hours googeling hoping I will stumble over the
> >(most likely rather simple) answer ?
 
> If you don't craft your question carefully, you won't get an useful
answer.
 
> The question, as originally posted, didn't really make sense in the
context
Reinhardt Behm <rbehm@hushmail.com>: Aug 30 10:01PM +0800

R.Wieser wrote:
 
 
> I can see that "server->h_addr" and "*server" should return the same
> address. The problem is that I can't get the latter to be accepted (and,
> as I'm a beginner, assumed I did something wrong), and I have no idea why.
 
Since we do not know what you function foo accepts as its parameter, we can
not really explain it. From what you write it seems it expect a pointer to a
char (char*). That would explain that the first form "server->h_addr" is
accepted by the compiler. But neither "*server" not "server" is a char
pointer. "*server" is a "struct hostent", assuming it has been set correctly
and "server" is a pointer to struct hostent.
 
To me it looks as if you do not know that in C (or C++) a pointer is not
just an address. It also has the property to point to a certain type.
 
So if your function foo expects a char pointer, meaning it is defined as
void foo(char *ptr);
You have to call it with a char pointer, not with a pointer to struct
anything.
This is true even if your variable "server" contains the address (as a bit
pattern) of the first byte of some struct hostent which by chance is also
the address of char or char array and the address of this char (server-
>h_addr) has the same bit pattern it is syntactically some thing different.
That willlead to your compiler complaining.
 
One tip: If you think it is to much effort to show something more of your
code,then just show us at least the definition of such functions because it
not irrelevant. Or show us the compiler message.

--
Reinhardt
scott@slp53.sl.home (Scott Lurndal): Aug 30 02:48PM


>Seems to be untrue. The compiler accepts "(unsigned char*) server" without
>even a warning. Using that result does not seem to cause any problems
>either.
 
Syntactically, perhaps. Semantically, it's catch as catch can - in this
case yours works by luck because the first field in the structure is
an array of characters.
 
If you have to cast something explicitly, you're generally doing the wrong thing.
 
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
}
 
struct hostent server;
 
void do_something_with_hostname(char *hostname);
 
 
do_something_with_hostname(server->h_name);
 
 
or
 
void do_something_with_hostent(struct hostent *); /* C definition */
void do_something_with_hostent(hostent *); /* C++ definition */
 
 
Note that the first field of struct hostent is a pointer to a
signed character. For historical reasons all strings in C and
C++ are considered to be arrays of signed characters, and the
compilers will complain if you attempt to pass server->h_name as
the argument of a function that takes 'unsigned char *' as an
argument.
 
From the GCC man page (only applies to the C compiler, not the C++ compiler)
 
Ideally, a portable program should always use "signed char" or "unsigned char" when it depends on
the signedness of an object. But many programs have been written to use plain "char" and expect it
to be signed, or expect it to be unsigned, depending on the machines they were written for. This
option, and its inverse, let you make such a program work with the opposite default.
Jerry Stuckle <jstucklex@attglobal.net>: Aug 30 11:00AM -0400

On 8/30/2016 9:43 AM, R.Wieser wrote:
 
> I can see that "server->h_addr" and "*server" *should* return the same
> address. The problem is that I can't get the latter to be accepted (and, as
> I'm a beginner, assumed I did something wrong), and I have *no* idea why.
 
Server->h_addr is a member of the structure. If it is an int, the code
will return an int. If it is a double, the code will return a double.
 
If it is an array, it will return the address of the first element in
the struct. This will be the same as the address of the struct - but
*only if this is the first element in the struct*. Should the struct
change at a later time, this will not be true (and will probably cause a
very difficult to find bug).
 
 
> Do you ?
 
> Regards,
> Rudy Wieser
 
No, because you haven't shown enough code. If the function takes a type
server*, then it should work as I explained. If it takes something
else, you shouldn't be passing a server* to it.
 
Function prototypes have a purpose - to indicate what type of parameters
the function accepts (and what it returns). Don't try to pass a B when
it expects an A. It doesn't work.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
legalize+jeeves@mail.xmission.com (Richard): Aug 30 04:31PM

[Please do not mail me a copy of your followup]
 
"R.Wieser" <address@not.available> spake the secret code
 
>> Here 'server' is a variable holding the address of a
>> 'hostent' structure. server *is* the address.
 
>I'm sorry, but I disagree with you. [...]
 
Then you don't yet understand the fundamentals of the language. Take
some on-line courses on C or C++ and learn the fundamentals of
pointer types first.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Aug 30 04:33PM

[Please do not mail me a copy of your followup]
 
"R.Wieser" <address@not.available> spake the secret code
>I'm in the habit of trying to ask my questions as exact as I can, needing it
>to have *it* answered. (that does not mean that I do not appreciate further
>hints in the same direction though!)
 
Please read "How to Ask Questions the Smart Way":
<http://www.catb.org/esr/faqs/smart-questions.html>
 
Your approach is directly at odds with getting the best way of
getting help from a programmer oriented newsgroup.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
jacobnavia <jacob@jacob.remcomp.fr>: Aug 30 07:36PM +0200

Le 30/08/2016 à 08:05, Gareth Owen a écrit :
 
> Actually, none of Jacob's "answers" are the most likely - what he knows
> about linux couldn't fill a hat. Doesn't stop him having opinions, of
> course.
 
I could say the same thing about you.
 
You do not know anything about me. I have been using linux since at
least 1995 or so.
 
But keep your opinion.
Manfred <noname@invalid.add>: Aug 30 08:10PM +0200

On 8/30/2016 11:33 AM, R.Wieser wrote:
>> the function receives a pointer to the structure ?
 
> Odd: several replies, but none that actually told me how its done. Is it
> some deep-dark secret that only masters of the trade are allowed to know ?
You had the correct answer, but you appeared to be too much busy
attacking the guy who gave you such correct answer in order to get it.
 
> hints in the same direction though!)
 
> Do I really need to waste hours googeling hoping I will stumble over the
> (most likely rather simple) answer ?
You can't hope to learn C and/or C++ by googleing around. Get a good
textbook instead.
Besides, many have already already given you the information you asked for.
But it looks as if your attitude got you convinced that they were all wrong.
 
Regards,
Manfred
"R.Wieser" <address@not.available>: Aug 30 07:32PM +0200

Jerry,
 
> No, because you haven't shown enough code. If the
> function takes a type server*, then it should work as
> I explained
 
Ehrmm .... In my first post in this thread I did show how I call the foobar
function, indicating I'm attempting to coerce the provided variable into an
unsigned char* before passing it on as the functions argument.
 
If the argument defined in the foobar function itself would be of a
different type I would (as far as I know) get a compile-time error because
of a mismatch. Hence, the function must look like this:
 
{undefined} foobar(unsigned char* argument , ....)
 
And it does. :-)
 
> Don't try to pass a B when it expects an A. It doesn't work.
 
Agreed.
 
Regards,
Rudy Wieser
 
 
-- Origional message:
 
Jerry Stuckle <jstucklex@attglobal.net> schreef in berichtnieuws
nq472u$mg3$1@jstuckle.eternal-september.org...
 
> >> Does this help?
 
> > I'm sorry, no. I read the same, and thought I understood.
 
> > You seem to say that what he wrote works, while the compiler on my
machine
> > still throws an compile-time error.
 
> > I can see that "server->h_addr" and "*server" *should* return the same
> > address. The problem is that I can't get the latter to be accepted
(and, as
> > I'm a beginner, assumed I did something wrong), and I have *no* idea
why.
"R.Wieser" <address@not.available>: Aug 30 08:34PM +0200

Richard,
 
> Then you don't yet understand the fundamentals of the language.
 
It could also be that I have a better understanding of what goes on below
than you do.
 
You see, you do not seem to understand the difference between a structures
address, and a variable *used as* a pointer *to hold* some other variables
address.
 
When you say "server *is* the address" you are right. But it is the address
of the "server" variable itself, not whatever it addres is stored as its
contents.
 
Granted, the language itself makes it easy for you to just forget such
fundamental things about it, and just throw something at it to get it
silently dereferenced to get at the actual structure.
 
Heck, why do you think both "." and "->" exist to access a strucures fields
?
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Richard <legalize+jeeves@mail.xmission.com> schreef in berichtnieuws
nq4cdc$c2b$1@news.xmission.com...
> pointer types first.
> --
> "The Direct3D Graphics Pipeline" free book
<http://tinyurl.com/d3d-pipeline>
"R.Wieser" <address@not.available>: Aug 30 07:14PM +0200

Scott,
 
> Syntactically, perhaps. Semantically, it's catch as catch
> can - in this case yours works by luck because the first
> field in the structure is an array of characters.
 
Are you sure about that ?
 
Wait, two things:
 
One: if what you say is true than I should not need to call the function
including coercing the "server" variable with "(unsigned char*)"
 
Two: the percieved type of a structure is the same as that of its first
field ?
 
... testing ...
 
Nope on both. The compiler complains about "hostent*" not being compatible
to "unsigned char*". And that sound logical to me.
 
> If you have to cast something explicitly, you're generally
> doing the wrong thing.
 
Agreed. In this case though its intentional.
 
> struct hostent {
[snip]
 
Thanks for the examples.
 
Well, thats something else: The "foobar" routine is not only for that one
structure, or for structures only for that matter. Comparable to the
"write" function I guess. You can write *any* data with it, as long as you
coerce the data's type into the one "write"'s argument expects.
 
And yes, If I would have wanted to use a fields data as its stored in there
it stands to reason to receive that field in an argument of the exact same
type (ignoring signed/unsigned differences here).
 
Regards,
Rudy Wieser
 
 
-- Origional message:
Scott Lurndal <scott@slp53.sl.home> schreef in berichtnieuws
s1hxz.19182$IH3.2168@fx40.iad...
> "R.Wieser" <address@not.available> writes:
> >Scott,
 
> >> >Odd: several replies, but none that actually told me how its done.
Is
> >it
> >> >some deep-dark secret that only masters of the trade are allowed to
know
> >?
 
> >> Pointers are the most basic of concepts in C, and C++.
 
> >I should have added the "</sarcasm>" tag, but felt like I would be
overdoing
 
> >> Casting your 'server' variable to an unsigned char pointer
> >> is incorrect in either language.
 
> >Seems to be untrue. The compiler accepts "(unsigned char*) server"
without
> case yours works by luck because the first field in the structure is
> an array of characters.
 
> If you have to cast something explicitly, you're generally doing the wrong
thing.
> the argument of a function that takes 'unsigned char *' as an
> argument.
 
> From the GCC man page (only applies to the C compiler, not the C++
compiler)
 
> Ideally, a portable program should always use "signed char" or
"unsigned char" when it depends on
> the signedness of an object. But many programs have been written to
use plain "char" and expect it
> to be signed, or expect it to be unsigned, depending on the machines
they were written for. This
> option, and its inverse, let you make such a program work with the
opposite default.
"R.Wieser" <address@not.available>: Aug 30 08:53PM +0200

Manfred,
 
> You had the correct answer, but you appeared to be too
> much busy attacking the guy who gave you such correct
> answer in order to get it.
 
If the answer was correct, why didn't it work for me ?
 
And pardon me, but I think I have mentioned that at least the first few
times. After that ? Yeah, how many times do you think I should be
repeating the same answer (to the same suggestions) ?
 
> Besides, many have already already given you the information
> you asked for. But it looks as if your attitude got you convinced
> that they were all wrong.
 
You mean you didn't notice that I've mentioned a number of times I got a
compile-time error when I tried the suggestions ? Are you really trying
to shoot the *messenger* here ?
 
I tried *everything* that was suggested. I even retried a number of things
I had already done, because maybe I did something wrong the last time (on my
own) but *this* time (doing it exactly as suggested) it would work.
 
But there is one thing I simply cannot stand: And that is when I say that
something doesn't work the other party keeps insisting that it does <full
stop>.
 
Next to that, at the same time not getting any suggestions to what I could
try to find the problem (in my understanding or in the code) is not funny
either (And no, all that was needed for that was present in the first
message).
 
Regards,
Rudy Wieser
 
 
Manfred <noname@invalid.add> schreef in berichtnieuws
nq4i5q$ofh$1@gioia.aioe.org...
 
> >> In short: How do I dereference that "server" variable so
> >> the function receives a pointer to the structure ?
 
> > Odd: several replies, but none that actually told me how its done. Is
it
> > some deep-dark secret that only masters of the trade are allowed to know
?
> attacking the guy who gave you such correct answer in order to get it.
 
> > And for some of you guys here: don't try to second-guess what I'm after.
> > I'm in the habit of trying to ask my questions as exact as I can,
needing it
> > to have *it* answered. (that does not mean that I do not appreciate
further
 
> You can't hope to learn C and/or C++ by googleing around. Get a good
> textbook instead.
> Besides, many have already already given you the information you asked
for.
> But it looks as if your attitude got you convinced that they were all
wrong.
"R.Wieser" <address@not.available>: Aug 30 05:01PM +0200

Chris,
 
> 19:16:59 UTC). 'server', as in:
 
> struct hostent *server;
 
> is declared as a pointer and can be passed as a pointer.
 
And I've told this group several times that IT DOESN'T WORK.
 
You can keep giving me the same "this should work" as many times as you
like, but my compiler is rather uninpressed by this against-the-facts
insistance, laughs about it a bit and just keeps throwing the compile-time
error. :-\
 
I do wish you guys could convince him otherwise though. :-)
 
> _is_ a pointer. You only need to dereference it if you want
> to obtain the structure's members. There is no secret here.
> It is the most basic C.
 
Absolutily.
 
So, why don't you tell me why "server->h_addr" works, but "*server" won't ?
 
> "a novice in regard to using C++ (GCC) *and* using linux"
> people thought that it was the specific gcc and linux issues
> you were unfamiliar with, not the basics of C and C++ itself.
 
Irrelevant. I think the question is clear enough. Regardless of if its a
high-level problem, or one as basic as this one. Heck, as its a problem
that has to do with "the basics of C and C++ itself" *everyone* here (above
the novice level) should know what to do about it, don't you think ?
 
> You gave the impression that you had done some
> windows programming.
 
I have. I didn't mention which language though. :-)
 
I mentioned to indicate that I'm no stranger to the logic of programming, or
its syntax. That does not mean I know everything, or cannot run into
stupid "you have to do it exactly *this* way" problems when encountering a
new language.
 
> The other difficulty is that you have an attitude problem
> which is considerably larger than your state of knowledge;
 
You think *I* have an attitude problem, when being confronted with a slew of
people who do not read (advising me to try stuff I wrote already I did), and
do not take "No, it doesn't work" for an answer ? You must be joking. :-|
 
> this [attitude] is going to get you into trouble, both in your code
 
That "in your code" I do not quite understand. My code has no problem with
who I am, what I look like or how many keyboards I go thru in an average
session. :-)
 
> and in your interactions on this news group.
 
True. But I don't mind to get rid of people who only know one answer, and
keep repeating that same answer over-and-over again because they simply
refuse to accept that it doesn't work. *That* attitude is simply
infuriating.
 
... and I guess that my getting "rather annoyed" shows in my answers. :-)
:-\
 
 
But please do explain why "server->h_addr" works, but "*server" not. I
could really use it. If it simply doesn't (for whatever reason) I will be
content too (though you stand a chance that I will say "Ha! Told you so!"
to several of this threads contributors. Sorry.)
 
Regards,
Rudy Wieser
 
P.s.
I think I gave enough code in my first post to reproduce the problem.
Currently I have not heard of anyone trying and either having a pro or con
experience. Odd.
 
 
-- Origional message:
Chris Vine <chris@cvine--nospam--.freeserve.co.uk> schreef in berichtnieuws
20160830135918.3d0861d6@dell.homenet...
Lynn McGuire <lynnmcguire5@gmail.com>: Aug 30 12:24PM -0500

On 8/29/2016 1:52 PM, Daniel wrote:
 
> I think the Unicode people have vastly simplified many people's lives.
 
> Admittedly, C++ has badly screwed this up.
 
> Daniel
 
Microsoft has a big hand in the screw up with their decision to go with wide characters. But the Unicode consortium is getting wacky
here lately with adding emoticons to Unicode.
http://blog.unicode.org/2016/06/unicode-90-emoji-available-for-adoption.html
 
Lynn
legalize+jeeves@mail.xmission.com (Richard): Aug 30 06:50PM

[Please do not mail me a copy of your followup]
 
>On 8/29/2016 1:52 PM, Daniel wrote:
>> Admittedly, C++ has badly screwed this up.
 
I think you have your history backwards. C and C++ predate unicode.
 
The general consensus seems to be that you should use std::string with
UTF-8 encoding to add basic unicode support. You can always get
fancier if you need it with Qt, wxWidgets, UCS, etc.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
mark <mark@invalid.invalid>: Aug 30 05:23PM +0200

On 2016-08-30 13:28, Chris Vine wrote:
> T t2 = c->t; // this is all you can do with C
 
> But there may be something else in the standard which precludes even
> this.
 
My reading of the standard is that this works if C (and all its members)
has a trivial default constructor. If not, it's undefined behavior. If C
has a trivial default constructor, storage allocation is enough to start
the lifetime, otherwise a constructor has to run.
 
§3.08/5 Object lifetime:
<<<
Before the lifetime of an object has started but after the storage which
the object will occupy has been allocated or, after the lifetime of an
object has ended and before the storage which the object occupied is
reused or released, any pointer that refers to the storage location
where the object will be or was located may be used but only in limited
ways. [...] Indirection through such a pointer is permitted but the
resulting lvalue may only be used in limited ways, as described below.
The program has undefined behavior if:
[...]
- the pointer is used to access a non-static data member or call a
non-static member function of the object, or
[...]
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: