Wednesday, February 25, 2015

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

JiiPee <no@notvalid.com>: Feb 25 09:05PM

On 25/02/2015 18:13, Jens Thoms Toerring wrote:
> wouldn't greet him with great friendliness but ask for him to
> be expelled before he ruins another evening.
 
> Regards, Jens
 
yes I agree, seems like you are right :).... even now he keeps sending
those messages, many of them in one day.
woodbrian77@gmail.com: Feb 25 11:34AM -0800


> When I pass port to gettaddrinfo I get the error.
> The same code works fine on Fedora/GCC 4.9, so I'm thinking
> it has something to do with fgets or strtok in Clang.
 
I no longer think it has to do fgets or strtok. If I
change port from being a char* to
 
char port[6];
 
and then do this:
 
::strcpy(port,::strtok(nullptr,"\n "));
 
It works fine on PC-BSD/Clang. So I guess it
has to do with a C string that isn't null terminated.
 
 
Brian
Ebenezer Enterprises - "Like a bad tooth and an
unsteady foot is confidence in a faithless man
in time of trouble." Proverbs 25:19
 
http://webEbenezer.net
woodbrian77@gmail.com: Feb 25 11:45AM -0800

On Wednesday, February 25, 2015 at 1:22:38 PM UTC-6, Mr Flibble wrote:
 
> using a C compiler and write C++ code (i.e. use std::string and such)
> when using a C++ compiler.
 
> /Flibble
 
Hi, Leigh,
 
I use some of the older stuff and std:string when using
a C++ compiler.
 
Brian
Ebenezer Enterprises - "It is better to live in a
corner of the roof than in a house shared with a
contentious woman." Proverbs 25:24
 
http://webEbenezer.net
jt@toerring.de (Jens Thoms Toerring): Feb 25 09:01PM


> There's a comment in this thread
 
> http://stackoverflow.com/questions/10291923/getaddrinfo-failing-with-error-servname-not-supported-for-ai-socktype-in-c
 
> about getline not removing a newline character.
 
I dodmn't find anything about that in there. But getline()
isn't supposed to remove the newline characterr at the end,
see for example
 
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html
 
> I'm using fgets
 
You just said getline() and now it's fgets()? fgets() is a
different beast since it doesn't try to allocated memory
for the string but stops reading when the buffer is full
(but always makes sure there's a terminating '\0'). It
also doesn't remove the trailing linefeed (if one was
found and fit into the buffer).
 
> and strtok:
 
> port=::strtok(nullptr,"\n ");
 
In the first call of strtok() you must pass it the
address of the string it's to be working on. Only if
you want further snippets of what that string con-
tains you use a NULL pointer. If this is your very
first call of it then it probably will return a NULL
pointer (but since this case isn't documented it may
also crash the program or returns something else, no-
body can know who hasn't taken a closer look at how it
is implemented).
 
Note that the string you pass to strtok() must be
modifiable - strtok() changes it by replaces de-
limiters by '\0' in that string So you can't e.g.
use the result of applying the c_str() method on a
std::string! You'd have to make a copy in that case.
 
And if it's just for removing a trailing linefeed
it's probaly simpler to do just something like
 
if ( port[ strlen( port ) - 1 ] == '\n' )
port[ strlen( port ) - 1 ] = '\0';
 
What you get from getline() should never have more than
a single trailing '\n' (but it may have none if it read
the last line in a file and there wasn'tx one in that
last line).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

bleachbot <bleachbot@httrack.com>: Feb 25 08:46PM +0100

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: