Sunday, August 30, 2009

comp.lang.c++ - 12 new messages in 8 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* g++ 3.4.5 doesn't zero-initialize - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/9c689fc29201ceec?hl=en
* Selection algorithm - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4d4bcabfc0f41d26?hl=en
* ===Welcome to comp.lang.c++! Read this first. - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/aa0892b0d59672d7?hl=en
* cin's input buffer - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/ee233797d52d183d?hl=en
* A subtle access issue (may be advanced :-) ) - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/cfa68deb52dc50f5?hl=en
* vaswer - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/e8940e27fd4a001c?hl=en
* Can anyone write this recursion for simple regexp more beautifully and
clearly than the braggarts - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/af69810e4522c696?hl=en
* Weird warning about data type range - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/c0fda54bd4ba1f60?hl=en

==============================================================================
TOPIC: g++ 3.4.5 doesn't zero-initialize
http://groups.google.com/group/comp.lang.c++/t/9c689fc29201ceec?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Aug 29 2009 8:29 pm
From: "Alf P. Steinbach"


Grr.

What's wrong with this code?

struct WndClassEx: WNDCLASSEX
{
WndClassEx(
cppx::WideString const& name,
Params const& params
)
: WNDCLASSEX()
{
cbSize = sizeof( WNDCLASSEX );
style = params.style();
lpfnWndProc = &DefWindowProc;
hInstance = params.module();
hCursor = ::LoadCursor( 0, IDC_ARROW );
hbrBackground = reinterpret_cast<HBRUSH>( COLOR_BTNFACE + 1 );
lpszClassName = name.cStr();
}

WndClassEx const* ptr() const
{
return this;
}
};

Answer: nothing in particular, at least when one knows that it's just a little
local helper class where 'name' arg has lifetime guaranteed to be enough.

But MinGW g++ doesn't zero-initialize the WNDCLASSEX as it should (this is a
plain struct with no constructor, provided by the Windows API).

Argh!

I knew old MSVC doesn't always zero-initialize /arrays/ when told to.

But I didn't know that g++ doesn't zero-initialize /structs/ when told to.

And by the way, the gdb debugger is driving me crazy. Ignoring breakpoints and
telling me the source code for some stack frame is at arbitrary location in
arbitrary file. And yes, optimizations turned off, which is another annoyance,
since g++ needs optimizations on to e.g. warn about uninitialized things.

Not to mention the Code::Blocks IDE's debugger output display, which doesn't
display anything of interest, just a bunch of info lines about internal details
of the debugger, and actively *swallows* trace output, which is what I'd need.

Happily it's possible to view a (nearly, almost, but of course not 100%)
complete log of the IDE's interaction with the brain-damaged debugger beast, and
there one can present stderr output. But. Oh well.

I need coffee.


- Alf

==============================================================================
TOPIC: Selection algorithm
http://groups.google.com/group/comp.lang.c++/t/4d4bcabfc0f41d26?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Aug 29 2009 9:22 pm
From: Digital Puer


On Aug 29, 8:29 am, Giuliano Bertoletti <gbe32...@libero.it> wrote:
> Hello,
>
> is there a better way to find the first k ranked elements of a vector of
> size n (with k < n) without sorting it first.
>
> Roughly I have n in the range [200..2000] and k = 3 or 4.
>
> Sorting would cost at least n*log(n) which in my opinion is a waste of time.
>
> Maybe I could hardwire a loop with a few comparisons for a given k (say
> k=3). I mean specialize a function for a certain k.
>
> Any ideas ?
>
> Cheers,
> Giulio.


You can do it in O(n) time. In the "Introduction to Algorithms"
book by Cormen, et al., 2001, there are two algorithms to find
the kth largest (or smallest) element in an unordered list.
One of them is a randomised algorithm with theta(n) expected /
O(n^2) worst case running time, and another is O(n) worst case.
The second one is quite difficult to implement and has a high
hidden constant (it implements a median-of-median search).

Anyways, once you find the kth largest element in O(n) time,
you can take one pass through the list in O(n) time to find
the elements that are smaller (or larger). Total running time
is O(n).

==============================================================================
TOPIC: ===Welcome to comp.lang.c++! Read this first.
http://groups.google.com/group/comp.lang.c++/t/aa0892b0d59672d7?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Aug 29 2009 9:30 pm
From: Shiva


Welcome to comp.lang.c++! Read this first.

This post is intended to give the new reader an introduction to reading
and posting in this newsgroup. We respectfully request that you read
all the way through this post, as it helps make for a more pleasant
and useful group for everyone.

First of all, please keep in mind that comp.lang.c++ is a group for discussion
of general issues of the C++ programming language, as defined by the ANSI/ISO
language standard. If you have a problem that is specific to a particular system
or compiler, you are much more likely to get complete and accurate answers in a
group that specializes in your platform. A listing of some newsgroups is given
at the end of this post.

The FAQ (Frequently Asked Question) list has a wealth of information for
both the new and veteran C++ programmer. No matter what your experience
level, you are encouraged to read the entire list, if only to familiarize
yourself with what answers are available to minimize redundant replies.
The comp.lang.c++ FAQ is available at http://www.parashift.com/c++-faq-lite/

If the FAQ list does not help, then many regular readers of this group
are happy to assist with problems of standard C++. We have only a few
requests that we ask be adhered to, for the benefit of all:

* Please put a short summary in the subject line. Descriptions such as
"HELP!!!!!!" are not helpful, and many regular posters ignore such
requests. A good example is, "Problem with Virtual Functions."

* State the question or the problem clearly and concisely. Describe what
you are trying to do, and the problem you are running into. Include all
relevant error messages.

* Include the smallest, complete and compilable program that exhibits your
problem. As a rule, posters in comp.lang.c++ will not do homework, but will
give helpful hints if you have shown some willingness to try a solution.

* comp.lang.c++ is forum for discussion, and as such some regular posters do
not give E-mail replies. Very often follow-ups to postings have corrections,
so plan on taking part in the discussion if you post a question. If you
do receive e-mail replies, it is considered polite to post a summary.

* Don't post in HTML format. Many readers of this newsgroup don't use
newsreaders which can handle HTML postings.

* If you have to include source code in your post, include the
source in the message body. Don't use attachments. A lot
of contributors to this newsgroup won't even notice the existence
of attachments or won't open them. You try to get any help
you can get, don't you?

Some netiquette topics which frequently crop up on comp.lang.c++ are
also answered in the FAQ.

* Should I post job advertisements and/or resumes on comp.lang.c++?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.10

* What if I really need a job; should I post my resume on comp.lang.c++?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.11

* What should I do to someone who posts something off-topic?
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.12

A note on comp.lang.c++ etiquette: Accuracy is valued very highly in this
newsgroup; therefore posts are frequently corrected, sometimes perhaps
too harshly, and often to the annoyance of new posters who consider the
correction trivial. Do not take it personally; the best way to fit in
with comp.lang.c++ is to express gratitude for the correction, move on,
and be more careful next time.

This is a very busy group, so these requests are designed to make it as
pleasant and efficient an experience as possible. We hope it proves
a valuable commodity to you.

A list of some Newsgroups :
Languages and Programming
-------------------------
comp.lang.c The C Programming Language
comp.lang.asm.x86 x86 assembly language programming
comp.programming Non-language specific programming
comp.graphics.algorithms Issues of computer graphics

Operating Systems
-----------------
comp.os.msdos.programmer DOS, BIOS, Memory Models, interrupts,
screen handling, hardware
comp.os.ms-windows.programmer.win32 MS/Windows: Mice, DLLs, hardware
comp.os.os2.programmer.misc OS/2 Programming
comp.sys.mac.programmer.misc Macintosh Programming
comp.unix.programmer General Unix: processes, pipes, POSIX,
curses, sockets
comp.unix.[vendor] Various Unix vendors

Microsoft VC++
-------------
microsoft.public.vc.language VC++ issues
microsoft.public.vc.mfc MFC Issues
microsoft.public.dotnet.languages.vc C++/CLR Issues
microsoft.public.dotnet.framework .Net Framework


Borland C++ Builder
-------------------
borland.public.cppbuilder.language Borland C++ Builder
borland.public.cpp.language
borland.public.cppbuilder

-Shiva
http://www.slack.net/~shiva/welcome.txt


Sun Aug 30 00:30:00 EDT 2009


==============================================================================
TOPIC: cin's input buffer
http://groups.google.com/group/comp.lang.c++/t/ee233797d52d183d?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Aug 29 2009 9:32 pm
From: aegis


Consider the following:

#include <iostream>
#include <string>

using namespace std;

int main(void)
{
int a, b, c;
cin >> a; cin >> b; cin >> c;
string s;
getline(cin, s);
return 0;
}

is there a newline hanging around cin's input buffer
for getline to accept and return immediately?

Because that is how the programming is behaving.


== 2 of 3 ==
Date: Sat, Aug 29 2009 10:06 pm
From: "Alf P. Steinbach"


* aegis:
> Consider the following:
>
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> int main(void)
> {
> int a, b, c;
> cin >> a; cin >> b; cin >> c;
> string s;
> getline(cin, s);
> return 0;
> }
>
> is there a newline hanging around cin's input buffer
> for getline to accept and return immediately?

Yes.

However, 'getline' consumes a newline.


Cheers & hth.,

- Alf


== 3 of 3 ==
Date: Sun, Aug 30 2009 12:14 am
From: Juha Nieminen


aegis wrote:
> cin >> a; cin >> b; cin >> c;

Btw, what's wrong with "cin >> a >> b >> c;"?

==============================================================================
TOPIC: A subtle access issue (may be advanced :-) )
http://groups.google.com/group/comp.lang.c++/t/cfa68deb52dc50f5?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Aug 29 2009 9:54 pm
From: Gil


On Aug 29, 3:11 am, "Alf P. Steinbach" <al...@start.no> wrote:
> I don't understand the complaint for the destructor.

At the point of definition of a virtual destructor, non-placement
operator delete shall be looked up in the scope of the destructor's
class
and if found shall be accessible and unambiguous.


== 2 of 3 ==
Date: Sat, Aug 29 2009 10:07 pm
From: "Alf P. Steinbach"


* Gil:
> On Aug 29, 3:11 am, "Alf P. Steinbach" <al...@start.no> wrote:
>> I don't understand the complaint for the destructor.
>
> At the point of definition of a virtual destructor, non-placement
> operator delete shall be looked up in the scope of the destructor's
> class
> and if found shall be accessible and unambiguous.

Where does it say that?


Cheers,

- Alf


== 3 of 3 ==
Date: Sat, Aug 29 2009 10:43 pm
From: Gil


On Aug 30, 1:07 am, "Alf P. Steinbach" <al...@start.no> wrote:
> * Gil:
>
> > On Aug 29, 3:11 am, "Alf P. Steinbach" <al...@start.no> wrote:
> >> I don't understand the complaint for the destructor.
>
> > At the point of definition of a virtual destructor, non-placement
> > operator delete shall be looked up in the scope of the destructor's
> > class
> > and if found shall be accessible and unambiguous.
>
> Where does it say that?
>
> Cheers,
>
> - Alf

ISO/IEC 14882:2003(E) 12.4.11, sorry it's late.

==============================================================================
TOPIC: vaswer
http://groups.google.com/group/comp.lang.c++/t/e8940e27fd4a001c?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Aug 29 2009 11:25 pm
From: ящдуп


http://puzdun.narod.ru/Automatic_Metod/
http://puzdun.narod.ru/
http://puzdun.narod.ru/Kniga_Dvorkin_/
http://puzdun.narod.ru/Mordi_Mor/
http://www.pizdun.50webs.com/index.html
http://www.pizdun.50webs.com/sitemap.txt
http://pimpis.makesgirlscrazy.com/

http://socoklik.narod2.ru/
http://socoklik.narod2.ru/foto_forum_nevesti_seks/
http://socoklik.narod2.ru/skachat_pesnyu_klounesko/
http://socoklik.narod2.ru/X_igra_na_nokia_classik/
http://socoklik.narod2.ru/s_plan/
http://blog.tatu.ru/pimpis/
http://blog.tatu.ru/pizda
http://pizda.bloges.org/
http://makitra.net/users/zhopa_popa/565.html
http://makitra.net/users/zhopa_popa/840.html
http://makitra.net/users/zhopa_popa/1217.html
http://pohuist.bravejournal.com/
http://www.liveinternet.ru/users/3402533/profile
http://www.liveinternet.ru/users/3402552/profile
http://www.liveinternet.ru/users/3402991/profile
http://www.liveinternet.ru/users/3402991/post109180490/
http://www.privet.ru/user/police_983
http://www.privet.ru/user/1234zz_022
http://www.privet.ru/user/jamo
http://www.privet.ru/user/znakomstva_intim

==============================================================================
TOPIC: Can anyone write this recursion for simple regexp more beautifully and
clearly than the braggarts
http://groups.google.com/group/comp.lang.c++/t/af69810e4522c696?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Aug 29 2009 11:30 pm
From: Richard Heathfield


In <h7cc1a$e6g$1@enyo.uwa.edu.au>, Chris McDonald wrote:

> Ed Morton <mortonspam@gmail.com> writes:
>
>>On Aug 28, 11:35=A0pm, bolega <gnuist...@gmail.com> wrote:
>>> This braggart admits that he had to put this code in TWO books and
>>> visit it twice to be explained. I am puting the excerpt from pp2-4
>>> of this book and the C code.
>
>>You should post this to comp.lang.c.
>
>> Ed.
>
> He did, and I smelt a Bilges sock puppet.

By the walks-like,swims-like,quacks-like theorem, I do see why you
think so, but I think we should be slow to make such accusations,
since they are so often wrong. I have never actually been accused of
being a sock puppet as far as I am aware, but I have certainly been
accused of running them (which I have never done, but of course those
who accuse me don't believe that).

People can and often do use similar styles, especially when responding
to people with whom they're perhaps not the best of friends. The
other day, an irregular poster, a guy - who'd been away for a while
and is unlikely to have become familiar with my occasional habit of
marking nilgewater with "nonsense snipped - nothing left" - made
precisely the same response. It would be easy to accuse /him/ of
being a sock puppet... and yet his name has been well-known in
another group for many years and he knows far more about that group's
subject than I do, and I vaguely recall having a few extended
disagreements with him in the past. He also posts from a different
continent, by the way.

Sock puppets undoubtedly happen, but they don't really matter because
what counts is not who says what, but what they say (and, to a
certain extent, how they say it). We might pay a lot of attention to
a name we recognise (e.g. if Donald Knuth started posting, we'd sit
up and take notice) - but *only* after it became obvious that it
wasn't some spotty teenager mucking about. And we judge that by
content. "By their fruits you shall know them" and all that.

In the current case, bolega (unknown name, to me at least) is slagging
off Brian Kernighan and Rob Pike (both names known to me) and their
book (which I've read). He starts with the word "braggart", and the
rest is similar ranting. It's just perfectly normal bilgewater of the
sort you often find on the Internet, but I don't see why we need to
accuse it of being nilgewater as well.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within

==============================================================================
TOPIC: Weird warning about data type range
http://groups.google.com/group/comp.lang.c++/t/c0fda54bd4ba1f60?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, Aug 30 2009 12:12 am
From: Juha Nieminen


Digital Puer wrote:
> #define IS_ALPHANUMERIC(x) ( \
> ((x) >= 48 && (x) <= 57 ) || \
> ((x) >= 65 && (x) <= 90 ) || \
> ((x) >= 97 && (x) <= 122) || \
> ((x) >= 192 && (x) <= 214) || \
> ((x) >= 216 && (x) <= 246) || \
> ((x) >= 248 && (x) <= 255) )
>
> string s = getLatin1Text();
> int len = s.size();
> for (int i = 0; i < len; i++)
> {
> if (! IS_ALPHANUMERIC(s.at(i)))
> {
> ...
> }
> }

I don't think that's doing what you want it to do.

A std::string contains chars, which are usually signed in most
systems. Values outside the ASCII range will thus have *negative*
values. When you do eg. a "x >= 248" what will happen is that x, which
is a signed char, will first be promoted to an int, and then compared to
248. Since 248 is larger than 127, the comparison will always yield false.

And btw, this is a great example where using a preprocessor macro
instead of an inline function is a *bad* idea. With the macro you will
be silently calling "s.at(i)" 12 times per call, rather than just once.
(Might not be so relevant if it was "s[i]", but with "s.at(i)" 11 of the
boundary checks will be completely useless.)

What you need is an inline function which takes a char as parameter,
then internally casts it to unsigned char, and then compares it to
unsigned char literals.


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: