Monday, February 29, 2016

Digest for comp.lang.c++@googlegroups.com - 13 updates in 5 topics

Daniel <danielaparker@gmail.com>: Feb 28 07:03PM -0800

On Sunday, February 28, 2016 at 3:19:24 AM UTC-5, Christian Gollwitzer wrote:
> Am 28.02.16 um 02:25 schrieb woodbrian77@gmail.com:
 
> > Please don't swear here.
 
> I don't understand, why you oppose against fucking.
 
Just guessing, but I don't think he's objecting to the word as such, I think
what he's objecting to is the dilution of the word, such as in "Fuck!" after
hitting your thumb with a hammer. The counter argument, of course, is that
research shows that the hypoalgesic effect of swearing can help reduce the
sensation of pain, c.f https://en.wikipedia.org/wiki/Hypoalgesic_effect_of_swearing.
 
Daniel
David Brown <david.brown@hesbynett.no>: Feb 29 09:04AM +0100

On 29/02/16 04:03, Daniel wrote:
> hitting your thumb with a hammer. The counter argument, of course, is that
> research shows that the hypoalgesic effect of swearing can help reduce the
> sensation of pain, c.f https://en.wikipedia.org/wiki/Hypoalgesic_effect_of_swearing.
 
You mean you think he'd be happy with swear words as long as they are
used solely for their literal meanings? I believe that would apply to
religious terms - I'm sure he has nothing against saying "Jesus" in
church, while objecting to its use as a hypoalgesic. I really don't
think that applies to "fuck", however.
 
No, I think Brian just has a particularly extreme view on swearing out
of context. Most of us have unwritten rules as to when we think
swearing is appropriate or not. When we watch a stand-up comedian, we
expect a good deal of colourful language. But we would be surprised to
hear a newsreader tell us "the economy has gone to fuck", even if it is
a clear, accurate and easily understood news item. And I think most of
us here feel that Usenet posts typically don't warrant the emphasis of
swearing - but the occasional light swear is fine. There are other
newsgroups were some posters are, quite frankly, unpleasant to read.
 
What distinguishes Brian is that he invariably reacts with a pointless
complaint for every tiny swear word that is usually unnoticed by anyone
else. And his complaints are invariably followed by someone else adding
more swearing, just to bug him - he never seems to learn, and his
complaint posts are far more annoying than any swearing in this newsgroup.
Juha Nieminen <nospam@thanks.invalid>: Feb 28 06:26PM

> Why people are insistent on trying to jam every possible library into
> the standard is beyond me.
 
That got me thinking: There are many things that do not really belong
into the C++ standard, but are nevertheless things that would be very
useful and people often request.
 
Perhaps a kind of compromise could work: A "secondary" specification
defined by the standard committee, of optional libraries. In other words,
libraries that a standard-conforming compiler is not forced to implement,
but if it does, then it has to implement it as specified (so that all
programs written to use said library will compile and work).
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Geoff <geoff@invalid.invalid>: Feb 28 02:05PM -0800

On Sun, 28 Feb 2016 09:19:10 +0100, Christian Gollwitzer
>through which we all were made. It is scientifically proven the cause of
>all our being.
 
> Christian
 
I think this might go back to the myth of Adam and Eve and original
sin. They were both given life without fucking being involved. Then
they ate of the tree of knowledge and were both fucked from that day
forward. Damned by God and driven from Eden, it's now a sin in the
eyes of religious fanatics to eat the wrong foods, fuck, wank off,
fuck thy neighbor's wife or do anything you fucking like of which the
pious might disapprove.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 29 11:21AM +0100

On 29.02.2016 09:04, David Brown wrote:
> [snip] his complaints are invariably followed by someone else adding
> more swearing, just to bug him - he never seems to learn,
 
There is the question of who is training whom. Pavlov's dog trained
Pavlov to ring a bell at feeding time. As a reward to Pavlov the dog
simply salivated each time Pavlov rang the bell at feeding time, and
after a few weeks or months Pavlov would ring the bell /every/ feeding time.
 
But while psychologists are so easy to train that even a quite famous
one could be trained by a dog, programmers who are Usenet denizens...
 
Well. Still. The question is open.
 
 
Cheers,
 
- Alf
Daniel <danielaparker@gmail.com>: Feb 29 02:46AM -0800

On Monday, February 29, 2016 at 5:21:41 AM UTC-5, Alf P. Steinbach wrote:
 
> Pavlov's dog trained Pavlov to ring a bell at feeding time. As a reward to
> Pavlov the dog simply salivated each time Pavlov rang the bell at feeding
> time.
 
As my background is in economics, I've always viewed the behavior of Skinner
and his rat as a freely entered into agreement: I'll give you food pellets
in exchange for you pull on a lever. I prefer that interpretation to that of
stimulus-responsibus.
 
> But while psychologists are so easy to train
 
My sister tells me that her psychology classmates successfully trained their
professor to stop pacing at the lectern, by putting down their notebooks and
pens and affecting disinterest whenever she stepped beyond a prescribed
boundary. Over time they narrowed the boundary, until stationary.
 
Daniel
scott@slp53.sl.home (Scott Lurndal): Feb 29 02:29PM

>"Current Proposals for C++17"
> https://meetingcpp.com/index.php/br/items/current-proposals-for-c17.html
 
Ah, such lovely thinking:
 
"Also, it shows that the committee is willing to not only add things, but also to deprecate,
and remove and break things in the future. Which is great..."
red floyd <no.spam@its.invalid>: Feb 29 10:09AM -0800

On 2/28/2016 10:26 AM, Juha Nieminen wrote:
> libraries that a standard-conforming compiler is not forced to implement,
> but if it does, then it has to implement it as specified (so that all
> programs written to use said library will compile and work).
 
Sort of like the various "annexes" to the Ada spec?
wij@totalbb.net.tw: Feb 29 08:13AM -0800

Xn project tries to develop a more uniform language that can be used in
almost anywhere. It can be used for general files (e.g. executables),
general communication language, or even for an alive program that can grow.
 
Xn project is licensed as Public Domain (Historical Fact Principle).
Anyone can start anything from Xn, as long as the historical fact is
maintained. Suggestions are also welcome.
https://sourceforge.net/projects/systemnode/
Cholo Lennon <chololennon@hotmail.com>: Feb 29 09:54AM -0300

On 02/25/2016 09:52 PM, Jerry Stuckle wrote:
 
> They list data sources. They say nothing about how the research was
> done. Nor do they discuss how the research was aggregated.
 
> Completely different topics.
 
My mistake, I wanted to say was what your are saying, how the research
was done (clearly the sources are listed, but without any additional
data. There is no link between the assertions and reddit or
stackoverflow for example)
 
Regards
 
--
Cholo Lennon
Bs.As.
ARG
Jerry Stuckle <jstucklex@attglobal.net>: Feb 29 09:32AM -0500

On 2/29/2016 7:54 AM, Cholo Lennon wrote:
> data. There is no link between the assertions and reddit or
> stackoverflow for example)
 
> Regards
 
Sorry, I misunderstood you.
 
One of the things that many miss is good science (and surveys are a
branch of statistics, which a science) requires repeatability - that is,
an experiment must be repeatable. To do that, there has to be enough
detail to recreate the experiment.
 
In surveys, this includes selection of the audience, wording of the
questions and aggregating the results. Any of them can skew the results
considerably.
 
And the sorry part is, here in the United States, politics is very often
based on questionable "surveys" - by politicians, media, lobbyists,
non-profits with a political agenda... the list goes on and on.
 
I guess it's why I'm so negative towards "surveys" like this. I've seen
way too many purposely biased to get the desired answer.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
alexo <alelvb@inwind.it>: Feb 29 02:16PM +0100

Il 14/02/2016 18:01, alexo ha scritto:
> Hello group,
 
> I've written for UNIX a little program [FLTK] that needs to send an
> order through e-mail.
 
[...]
 
I've found the bug!
 
PEBKAC !!
 
cutting and pasting the payload source function I had forgot to select a
part of it. The compiler told me I had left an unmatched brace so I
added it leaving a mangled function that was doing nothing. And so the
infinite apparent data transmission.
 
All is well that ends well
 
Thank you all for your help and patience.
David Brown <david.brown@hesbynett.no>: Feb 29 09:12AM +0100

On 28/02/16 23:57, JiiPee wrote:
>> 1
 
> Not sure how safe this approach is and is it recommended? I mean, what
> if somebody changes EAST to say, 5 later on?
 
It is not safe if the enumerated states are anything other than
contiguous from 0, or if they don't have an appropriate order in their
definition. It also involves a good deal more casts if you are using
strongly typed enums.
 
I don't like the idea of putting an extra marker like TOP into the
enums. TOP is /not/ a direction - yet you (Stefan) have told the
compiler that it /is/ a direction, because it is a member of the type.
Don't lie to your compiler, or to your readers. It also means that you
lose the help your compiler could give you in spotting errors, such as
using the "-Wswitch-enum" warning in gcc.
 
Making the ++ operator explicit with a switch statement solves all these
problems, though it is more verbose.
 
 
> In any case, I think with this approach there should be heavy comments
> near direction to warn about this, that not to change the integer values.
 
Agreed.
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.

Fwd: 一個比日本更噁心的民族誕生了!



Sent from my iPad


Sent from my iPad

Begin forwarded message:

From: Sharon Kahn <sharon62kahn@gmail.com>
Date: February 29, 2016 at 9:11:16 AM CST
Subject: Fwd: 一個比日本更噁心的民族誕生了!






Subject: Fwd: 一個比日本更噁心的民族誕生了!

Sunday, February 28, 2016

Digest for comp.lang.c++@googlegroups.com - 10 updates in 4 topics

JiiPee <no@notvalid.com>: Feb 28 09:23PM

On 28/02/2016 19:38, Bob Langelaan wrote:
> enum Directions { NORTH, EAST, SOUTH, WEST };
 
you can do something like this:
Directions kk = NORTH;
kk = (Directions)(kk + 1);
Vir Campestris <vir.campestris@invalid.invalid>: Feb 28 09:43PM

On 28/02/2016 19:38, Bob Langelaan wrote:
 
> but I get the error:
 
> "Error (active) this operation on an enumerated type requires an applicable user-defined operator function"
 
> I thought this was supposed to work. Is this a bug or am I remembering wrong?
 
IIRC it works in C.
 
When you increment an enum you get an int (usually) - the underlying
type for an enum. You then have to cast it back to the enum type - as
JiiPee showed - or you can make an operator++ function for the enum type.
 
Directions operator++(const Directions old)
{
if (Direction == WEST)
return North;
else
return static_cast<Directions>(++old);
}
 
(and I haven't even fed that to a compiler so it's probably wrong)
 
Andy
Victor Bazarov <v.bazarov@comcast.invalid>: Feb 28 04:51PM -0500

On 2/28/2016 2:38 PM, Bob Langelaan wrote:
 
> but I get the error:
 
> "Error (active) this operation on an enumerated type requires an applicable user-defined operator function"
 
> I thought this was supposed to work. Is this a bug or am I remembering wrong?
 
You're remembering wrong, or incompletely. In order to use ++ with a
user-defined type, one needs to define one's own operator. What do you
think a ++ would do if you gave your enumeration constants specific
values, like
 
enum Directions { NORTH = 10, EAST = 100, SOUTH = 1000, WEST = 10000 };
 
? What would it do for 'WEST'? Circle back or become an unnamed value
(integral 4)? There is no default behavior for user-defined types.
 
As your compiler suggests, define your own operator:
 
Direction& operator++(Direction& d) {
switch (d) {
case NORTH: d = EAST; break;
case EAST: d = SOUTH; break;
case SOUTH: d = WEST; break;
case WEST: d = NORTH;
}
return d;
}
 
V
--
I do not respond to top-posted replies, please don't ask
JiiPee <no@notvalid.com>: Feb 28 10:54PM

On 28/02/2016 21:51, Victor Bazarov wrote:
> return d;
> }
 
> V
 
 
yes I think this is the safest way. adding +1 can lead to errors later
on if somebody changes their integer values.
so: enum + 1 I think think is not so good idea....
Bob Langelaan <bobl0456@gmail.com>: Feb 28 02:54PM -0800

On Sunday, February 28, 2016 at 1:51:14 PM UTC-8, Victor Bazarov wrote:
 
> V
> --
> I do not respond to top-posted replies, please don't ask
 
Thanks muchly :)
 
Bob
JiiPee <no@notvalid.com>: Feb 28 10:57PM

On 28/02/2016 22:06, Stefan Ram wrote:
> 3
> 0
> 1
 
Not sure how safe this approach is and is it recommended? I mean, what
if somebody changes EAST to say, 5 later on?
In any case, I think with this approach there should be heavy comments
near direction to warn about this, that not to change the integer values.
Geoff <geoff@invalid.invalid>: Feb 28 02:05PM -0800

On Sun, 28 Feb 2016 09:19:10 +0100, Christian Gollwitzer
>through which we all were made. It is scientifically proven the cause of
>all our being.
 
> Christian
 
I think this might go back to the myth of Adam and Eve and original
sin. They were both given life without fucking being involved. Then
they ate of the tree of knowledge and were both fucked from that day
forward. Damned by God and driven from Eden, it's now a sin in the
eyes of religious fanatics to eat the wrong foods, fuck, wank off,
fuck thy neighbor's wife or do anything you fucking like of which the
pious might disapprove.
"Öö Tiib" <ootiib@hot.ee>: Feb 28 02:27PM -0800

On Sunday, 28 February 2016 23:17:31 UTC+2, Dombo wrote:
 
> If mixing UI and program logic is really a big concern and you cannot
> rely on the discipline of the developers you'd much better of using
> another programming language for the UI.
 
Good idea, typically HTML5 is best candidate now. Maybe in few years C++
again built with asm.js. Qt 5 has also now gone to separate language
for GUI with its QML. Unfortunately that makes 3 layers: application
logic, fishbones of that Qt and QML.
 
> unnecessarily hard just stimulates people to just do everything in the
> UI code to avoid having to write error-prone/no-added-value glue code to
> interface with other parts of the program.
 
What are the better ways? I sometimes suggest separate processes for
UI and business logic but that makes interfacing even harsher so I
don't think you meant that.
 
The product gets actually produced quicker that way since UI-less
application logic is easier to unit test and automatic test and any
peck or panic about UI features does not accidentally screw
application logic up. It is not hard to sell such architecture to
shareholders since there is prospect to put business logic into
"cloud", UI into "web" or "apps" or whatever the current buzzwords
are.
 
> container types as used for the GUI part, apparently Qt didn't thought
> it was necessary to introduce more incompatible string and container
> classes to make the distinction between UI and business logic clear.
 
I agree. There is odd megalomania on case of Qt. Most things that Qt
incorporates besides GUI are not hard to dump however. Those have
better alternatives freely available.
 
> languages is the inconsistent mess of (naming) conventions, strings,
> containers...etc you get confronted with if you use multiple libraries
> from various sources. Not a good thing in my book.
 
That is very same with other languages as well. Everybody wants to
have some personal "style". More like samurais than engineers.
guinness.tony@gmail.com: Feb 28 02:19PM -0800

On Saturday, 27 February 2016 18:22:44 UTC, alexo wrote:
> on button pressing.
 
> any help is welcome and appreciated
 
> thank you
 
It seems that your program runs in an event-driven framework
(which the toy program did not).
 
In such an environment, you almost certainly need to be using
the curl_multi_xxxx() function set: this allows the transfer to
be made asynchronously, eventually notifying you of the final
success/failure status (through an event or callback function)
without holding up your original event handler.
 
In the last project in which we used libcurl, I seem to recall
comments in the code to the effect that curl_easy_perform()
must only be called from the same thread that called
curl_easy_init(), otherwise unexpected behaviour would ensue.
[I've not recently checked the libcurl documentation to
determine the validity of those warnings.]
In an event-driven runtime framework, this same-thread
guarantee cannot always, if ever, be met.
 
I advise looking into using libcurl-multi.
 
https://curl.haxx.se/libcurl/c/libcurl-multi.html
ram@zedat.fu-berlin.de (Stefan Ram): Feb 28 10:06PM

> }
> return d;
> }
 
Yes. But, /if/ the numerical values are appropriate,
then one might also:
 
#include <iostream>
#include <ostream>
 
enum direction { NORTH, EAST, SOUTH, WEST, TOP };
 
direction operator+( const direction d, int const n )
{ return static_cast< direction >
( ( static_cast< int >( d )+ n )% static_cast< int >( TOP ) ); }
 
int main()
{ direction x( NORTH );
for( int i = 0; i < 9; ++i )::std::cout <<( x = x + 1 )<< '\n'; }
 
1
2
3
0
1
2
3
0
1
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.

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

woodbrian77@gmail.com: Feb 27 05:25PM -0800

On Friday, February 26, 2016 at 6:54:39 PM UTC-6, Richard wrote:
 
Richard,
 
Please don't swear here.
 
Brian
Ebenezer Enterprises
http://webEbenezer.net
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 28 02:15AM

> On Friday, February 26, 2016 at 6:54:39 PM UTC-6, Richard wrote:
 
> Richard,
 
> Please don't swear here.
 
'This video may contain sexual swearwords, I'm afraid. There are 28
'fucks'. Including that one 29. Ah, fuck it, make it 30.' -- Paul Calf
 
https://www.youtube.com/watch?v=42UCpOzTbNU
 
/Flibble
Gareth Owen <gwowen@gmail.com>: Feb 28 07:33AM

> fucks'. Including that one 29. Ah, fuck it, make it 30.' -- Paul Calf
 
> https://www.youtube.com/watch?v=42UCpOzTbNU
 
> /Flibble
 
"As such this video may contain frequent sexual swearwords, such as
bollocks, and wanke..." https://www.youtube.com/watch?v=15niBO3ZaQo
Christian Gollwitzer <auriocus@gmx.de>: Feb 28 09:19AM +0100

> On Friday, February 26, 2016 at 6:54:39 PM UTC-6, Richard wrote:
 
> Richard,
 
> Please don't swear here.
 
I don't understand, why you oppose against fucking. It is the one thing
through which we all were made. It is scientifically proven the cause of
all our being.
 
Christian
David Brown <david.brown@hesbynett.no>: Feb 28 04:43PM +0100

On 27/02/16 17:45, 嘱 Tiib wrote:
 
> Experimental implementation is not carved into rock and its makers
> knew that it has to be likely rewritten. People who used such for
> real product knew with what they risk.
 
Yes, there is a bit of trial-and-error here to see what works in
practice. Some people will like the idea enough to risk using the
experimental versions - and their feedback will help shape the final
versions. I understand that this will take time - but I hope it will
not be long before a final agreed version can be made.
 
> I am more worried that adding innovations like Modules, Concepts and
> Reflection at once will cause serious headache of integrating those
> features into whole.
 
Certainly modules and concepts are being tried out as experimental
features in compilers - hopefully that means they will be reasonably
good when they make the standards. It would be unfortunate if they were
added and then found to have some fundamental problem.
"Öö Tiib" <ootiib@hot.ee>: Feb 28 10:24AM -0800

On Sunday, 28 February 2016 17:44:09 UTC+2, David Brown wrote:
> features in compilers - hopefully that means they will be reasonably
> good when they make the standards. It would be unfortunate if they were
> added and then found to have some fundamental problem.
 
I wonder if anyone is trying all the three at once? Integration involves
always issues, rough edges and dim corners. Dealing with those may add
complexities and complexities may be in conflict with faster and
better scalable builds, better diagnostics, easier definition checking,
more transparency, better structure, better type-safety (IOW the
motivation of adding those features).
Juha Nieminen <nospam@thanks.invalid>: Feb 28 06:26PM

> Why people are insistent on trying to jam every possible library into
> the standard is beyond me.
 
That got me thinking: There are many things that do not really belong
into the C++ standard, but are nevertheless things that would be very
useful and people often request.
 
Perhaps a kind of compromise could work: A "secondary" specification
defined by the standard committee, of optional libraries. In other words,
libraries that a standard-conforming compiler is not forced to implement,
but if it does, then it has to implement it as specified (so that all
programs written to use said library will compile and work).
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 28 07:42PM

On 28/02/2016 07:33, Gareth Owen wrote:
 
>> /Flibble
 
> "As such this video may contain frequent sexual swearwords, such as
> bollocks, and wanke..." https://www.youtube.com/watch?v=15niBO3ZaQo
 
Interesting that "wanker" is acceptable on the BBC whilst, I think,
"cunt" is not but this is probably due to the fact that "cunt" is the
strongest swear word in the English language. ITV dubbed out the "cunt"
in "Can I get any of you cunts a drink?" when they showed Shaun Of The
Dead once.
 
/Flibble
Gareth Owen <gwowen@gmail.com>: Feb 28 09:04PM


> Interesting that "wanker" is acceptable on the BBC whilst, I think,
> "cunt" is not but this is probably due to the fact that "cunt" is the
> strongest swear word in the English language.
 
Well, there's no flat list of "allowed v. not allowed". The context is
taken into consideration. I do remember ITV once replacing the word
"Penis" with "Twinkie" in Ghostbusters, tho.
Dombo <dombo@disposable.invalid>: Feb 28 10:18PM +0100

Op 27-Feb-16 om 20:23 schreef Öö Tiib:
 
> It is actually good. It makes clear interface where your program logic
> layer (that does not use UI classes) touches with UI (that does not
> use standard library).
 
If mixing UI and program logic is really a big concern and you cannot
rely on the discipline of the developers you'd much better of using
another programming language for the UI.
 
> intermixed with GUI and I congratulate GUI toolkit that makes it as
> painful as possible for those who let so different responsibilities
> to diffuse all over the code base.
 
I'm all for keeping a clear separation between UI and business logic.
But there are better ways to accomplish that than introducing
incompatible types. Making interfacing with the standard library
unnecessarily hard just stimulates people to just do everything in the
UI code to avoid having to write error-prone/no-added-value glue code to
interface with other parts of the program.
 
And lets be honest; keeping the UI code separate from business logic is
not the reason why those GUI toolkits have their own string and
container classes. Just look at Qt, it is (unfortunately) not just a GUI
library, but provides classes for just about anything they could think
of, including lots of stuff that has absolutely nothing to do with UI.
And guess what; those non-UI classes use the same string types and
container types as used for the GUI part, apparently Qt didn't thought
it was necessary to introduce more incompatible string and container
classes to make the distinction between UI and business logic clear.
 
One of the things that separates C++ from other modern programming
languages is the inconsistent mess of (naming) conventions, strings,
containers...etc you get confronted with if you use multiple libraries
from various sources. Not a good thing in my book.
Ian Collins <ian-news@hotmail.com>: Feb 29 10:18AM +1300

Mr Flibble wrote:
> strongest swear word in the English language. ITV dubbed out the "cunt"
> in "Can I get any of you cunts a drink?" when they showed Shaun Of The
> Dead once.
 
Before or after The Thick of It?
 
This one is still hard to best:
 
https://www.youtube.com/watch?v=JaY7VTftPdY
 
--
Ian Collins
JiiPee <no@notvalid.com>: Feb 28 01:27PM

We all know the vector class does not have a function to delete extra
memory from the vector. So my first question is that why is it not
there? :) Is there a good reason, as I think its many times needed.
 
Secondly, we can do it ouselves, and everybody recommends:
 
(deleting extra memory from a)
vector<int> a{3,4,7,5,8,7};
a.push_back(55);
 
vector<int> temp(a);
a.swap(temp);
 
so now a has capacity 7. But I was just thinking, that can't we just do
a move:
vector<int> temp(a);
a = std::move(temp);
 
becouse move will now make sure a is excatcly temp. Why we would like to
copy stuff from a to temp (with swap) bce temp is not needed anyway ...
kind of extra work? What is the reason behind swap here?
JiiPee <no@notvalid.com>: Feb 28 02:38PM

does anybody know in what situation shrink_to_fit would not do the job
of taking off the extra memory exactly like asked? I tested, and it
always did take off the extra memory. But we know its not guaranteed, so
in what situation it would not do it?
 
On 28/02/2016 13:27, JiiPee wrote:
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 06:53PM +0200

On 28.02.2016 15:27, JiiPee wrote:
> We all know the vector class does not have a function to delete extra
> memory from the vector.
 
You mean shrink_to_fit() is not guaranteed to work? I bet when it does
not then it has good reasons not to.
 
> So my first question is that why is it not
> there? :) Is there a good reason, as I think its many times needed.
 
For example? It most probably means an extra copy of the whole array for
no obvious benefit.
 
If one is working in tight environment where every byte is counted, then
one does not over-allocate arrays in the first place, so there will be
no need to shrink them. Instead, one would use e.g. reserve() to
allocate the correct amount beforehand.
 
> a move:
> vector<int> temp(a);
> a = std::move(temp);
 
That's basically just as good. The swap idiom just predates the C++11
move. And if you have C++11 then you will have shrink_to_fit() which
most probably does the same in a more direct way, so there is no need to
use move.
 
 
> becouse move will now make sure a is excatcly temp. Why we would like to
> copy stuff from a to temp (with swap) bce temp is not needed anyway ...
> kind of extra work? What is the reason behind swap here?
 
Swap was a workaround to *avoid* extra copy and extra work in pre-C+11
when there was no move.
"Öö Tiib" <ootiib@hot.ee>: Feb 28 09:38AM -0800

On Sunday, 28 February 2016 16:38:55 UTC+2, JiiPee wrote:
> of taking off the extra memory exactly like asked? I tested, and it
> always did take off the extra memory. But we know its not guaranteed, so
> in what situation it would not do it?
 
Implementations are allowed to ignore it for sake of optimizations.
 
Imagine memory management that actually allocates only as multiples
of 32 bytes or the like. In reality most implementations have memory
management with such constraints.
 
As result the 'std::vector<char> hi{'H','e','l','l','o',0};' has
two choices:
1) to claim that its capacity is 6 (despite it got 32 bytes)
2) to put extra effort into telling honestly that the capacity is 32.
Most implementations have chosen to ignore the extra and to
do 1). It is simpler to implement and less stupid questions and
who really cares that it is less optimal.
Juha Nieminen <nospam@thanks.invalid>: Feb 28 06:32PM

> We all know the vector class does not have a function to delete extra
> memory from the vector. So my first question is that why is it not
> there? :) Is there a good reason, as I think its many times needed.
 
std::vector::shrink_to_fit() does exactly that, if the underlying
memory management system supports reducing the size of an alloction.
(If the underlying memory management system does not support it, which
is sometimes the case, then that function does nothing.)
 
The reason why it's optional is, obviously, because historically not
all systems support resizing of allocated blocks of memory (either
larger or smaller). The only way was/is to allocate a new block and
copy all the values there.
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 28 09:32PM +0100

On 28.02.2016 19:32, Juha Nieminen wrote:
>> there? :) Is there a good reason, as I think its many times needed.
 
> std::vector::shrink_to_fit() does exactly that, if the underlying
> memory management system supports reducing the size of an alloction.
 
No no.
 
shrink_to_fit can and will in general allocate a new buffer, when the
original capacity is way too large.
 
 
> (If the underlying memory management system does not support it, which
> is sometimes the case, then that function does nothing.)
 
No no.
 
 
> all systems support resizing of allocated blocks of memory (either
> larger or smaller). The only way was/is to allocate a new block and
> copy all the values there.
 
Yes, I agree. :)
 
 
Cheers!,
 
- Alf
Bob Langelaan <bobl0456@gmail.com>: Feb 28 11:38AM -0800

I have defined a variable m_Dir of the type:
 
enum Directions { NORTH, EAST, SOUTH, WEST };
 
I thought I should be able to increment the variable:
 
++m_Dir;
 
but I get the error:
 
"Error (active) this operation on an enumerated type requires an applicable user-defined operator function"
 
I thought this was supposed to work. Is this a bug or am I remembering wrong?
 
Thanks,
Bob
Jerry Stuckle <jstucklex@attglobal.net>: Feb 27 08:15PM -0500

On 2/27/2016 6:33 PM, Paavo Helde wrote:
>> is it owned by Borland any longer. It has changed significantly since
>> Borland owned it.
 
> So... and which part of this means "eventual failure of [Turbo C++]"?
 
The part where Borland failed with it.
 
> been name changes and sell-offs (to shake off some alleged bad
> reputation or not, I don't know), but as far as I can see there is no
> "eventual failure".
 
The current product is nothing like the failed one. Just because there
is a derivative does not mean the original was successful.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: Feb 27 06:21PM -0500

On 2/27/2016 5:47 PM, Paavo Helde wrote:
 
> Except that it is not dead. Nowadays this is called Embarcadero
> C++Builder and the last release according to Wikipedia was on 31 Aug.
> 2015 (C++Builder 10 Seattle (23)).
 
C++ Builder is a derivative of Turbo C++, but it is not Turbo C++, nor
is it owned by Borland any longer. It has changed significantly since
Borland owned it.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
David Brown <david.brown@hesbynett.no>: Feb 28 03:26PM +0100

On 27/02/16 19:14, 嘱 Tiib wrote:
 
> I meant it more generally. People who ever want to port their code to
> different version or different compiler or different platform should
> be prepared that there are some noisy and some silent breaking changes.
 
Agreed.
 
> representation of bitfield some are because of defects. Defects are
> most likely in the code compiled but sometimes also in previous or
> new implementation.
 
Agreed. It is important to remember that "implementation defined
behaviour" can vary between compiler versions. New compiler versions
can have new bugs in the compiler - they can also have new optimisations
or changes to code generation that causes different behaviour in code
that had undefined behaviour but happened to work on the other compiler.
 
For the kind of development I do, I rarely change compiler in the middle
of a project - and if I have to make changes to an old project, I first
bring up the old tools and check that I can do a bit-perfect rebuild of
the old version.
 
Marcel Mueller <news.5.maazl@spamgourmet.org>: Feb 28 10:16AM +0100

On 27.02.16 21.48, Öö Tiib wrote:
 
> I see you use string literals to initialize 'Name' so I don't
> understand why there is that mutable array and that L, do you want
> to dynamically modify it?
 
No, but the same structure is used for other lookup tables too.
The size differs from table to table and I did not want to define a new
type for each purpose.
 
 
> 'boost::variant<paramtype1,paramtype2,paramtype3>'. You must know
> anyway all the different types of parameters when you initialize
> that 'opcodeMap' of yours.
 
Not that pretty since there are about a dozen types, but true. The do
not change often. I could use a typedef.
 
> Btw words like "Map" and "List" may be
> misleading in name of variable since readers sometimes assume
> underlying container.
 
Well, basically it is a map, implemented as sorted array.
The compiler will tell, if someone tries to invoke .begin() ;-)
But since the member is private this is unlikely.
 
 
> No ... union is not type-safe, it is type-punning.
 
With an appropriate C++ wrapper it is safe.
 
>> Could this be expressed type safe in C++11, without the need to deal
>> with pointers, new and delete for each line?
 
> Unfortunately the 'variant' is not in C++11.
 
Hmm, the additional dependency to the boost library could cause some
harm with respect to portability. Especially because I require constexpr
support.
 
 
Marcel
Marcel Mueller <news.5.maazl@spamgourmet.org>: Feb 28 10:31AM +0100

On 27.02.16 21.58, Alf P. Steinbach wrote:
> };
 
> // ... later
> Op_entry e{ "Blah!", [=](){ Parser::assembleADD( Inst::A_ADD ); } };
 
Indeed, I didn't think of lambdas.
 
But is this still constexpr? I.e. can this still be a table of compile
time constants in the rodata segment?
If the objects have to be created at application start, it would be
quite costly, there are thousands (not only for op-codes). Target is a
Pi 1, where performance is always an issue.
 
 
Marcel
"Öö Tiib" <ootiib@hot.ee>: Feb 28 03:12AM -0800

On Sunday, 28 February 2016 11:31:39 UTC+2, Marcel Mueller wrote:
> If the objects have to be created at application start, it would be
> quite costly, there are thousands (not only for op-codes). Target is a
> Pi 1, where performance is always an issue.
 
Lambdas are not allowed in constexpr expressions by C++14. There is
proposal N4487. http://open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4487.pdf
I'm not sure what versions of what compilers support it.
"Öö Tiib" <ootiib@hot.ee>: Feb 28 05:03AM -0800

On Sunday, 28 February 2016 11:16:35 UTC+2, Marcel Mueller wrote:
 
> No, but the same structure is used for other lookup tables too.
> The size differs from table to table and I did not want to define a new
> type for each purpose.
 
Do you modify that 'Name' dynamically in other lookup tables then?
 
> > that 'opcodeMap' of yours.
 
> Not that pretty since there are about a dozen types, but true. The do
> not change often. I could use a typedef.
 
Yes, but how else to reach type-safety? All the allowed types
have to be listed somewhere for wrong type to cause code
being ill-formed with diagnostic.
 
> But since the member is private this is unlikely.
 
> > No ... union is not type-safe, it is type-punning.
 
> With an appropriate C++ wrapper it is safe.
 
Writing such wrapper around union is quite interesting task that is why
there are so lot of different variant classes.
 
 
> Hmm, the additional dependency to the boost library could cause some
> harm with respect to portability. Especially because I require constexpr
> support.
 
I am not sure how you mean constexpr and portability almost in same
sentence. Constexpr was sort of careful in C++11 and C++14 loosened it
up only slightly. Couple latest versions of top compilers support it
and only Clang is bit ahead of time with it.
 
My opinion is that if you need best portability and best tested
thing then Boost.Variant, if you need better constexpr support
then Eggs.Variant. Those have quite close interfaces. Both are
licensed under boost's "do whatever you want just don't change the
license".
 
Eggs.Variant's repo includes interesting Catch unit
test framework if you don't have one. Add unit tests what you
really want and run those on targets that you target.
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.

Saturday, February 27, 2016

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

Jerry Stuckle <jstucklex@attglobal.net>: Feb 27 04:40PM -0500

On 2/27/2016 10:34 AM, David Brown wrote:
> bleeding-edge. (I would prefer not to name the tools as I have only
> helped out another developer here, rather than studying the tool in
> detail.)
 
I remember the Borland Turbo C++ compiler back in the early-mid 90's.
They never admitted they had any bugs in their compilers, but every year
or so they came out with another version (which you had to pay for) that
"fixed" most of the bugs. Except you then had to find a whole new set
of bugs.
 
Plus they charged for reporting a bug. I remember one basic C++ course
where a student's code wasn't working right. In my hotel that night, I
found the problem - he was passing an object by reference, and on return
the object's destructor was called. I called Borland to report it, and
they wanted something like $35 or $40 at that time just to let them know
they had a bug. I didn't pay, but the next version had it fixed. New
bugs in it, though.
 
I actually think this was a big cause of the eventual failure of their
compiler. It was cheap, fast, and once you knew the bugs, pretty good.
But it got a bad reputation for having bugs; one that was only partly
deserved.
 
The bottom line is - you aren't going to hide bugs. They will be found,
and people talk.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 12:47AM +0200

On 27.02.2016 23:40, Jerry Stuckle wrote:
> bugs in it, though.
 
> I actually think this was a big cause of the eventual failure of their
> compiler.
 
Except that it is not dead. Nowadays this is called Embarcadero
C++Builder and the last release according to Wikipedia was on 31 Aug.
2015 (C++Builder 10 Seattle (23)).
Jerry Stuckle <jstucklex@attglobal.net>: Feb 27 06:21PM -0500

On 2/27/2016 5:47 PM, Paavo Helde wrote:
 
> Except that it is not dead. Nowadays this is called Embarcadero
> C++Builder and the last release according to Wikipedia was on 31 Aug.
> 2015 (C++Builder 10 Seattle (23)).
 
C++ Builder is a derivative of Turbo C++, but it is not Turbo C++, nor
is it owned by Borland any longer. It has changed significantly since
Borland owned it.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Paavo Helde <myfirstname@osa.pri.ee>: Feb 28 01:33AM +0200

On 28.02.2016 1:21, Jerry Stuckle wrote:
 
> C++ Builder is a derivative of Turbo C++, but it is not Turbo C++, nor
> is it owned by Borland any longer. It has changed significantly since
> Borland owned it.
 
So... and which part of this means "eventual failure of [Turbo C++]"?
 
Of course it has evolved significantly over the years, and there have
been name changes and sell-offs (to shake off some alleged bad
reputation or not, I don't know), but as far as I can see there is no
"eventual failure".
"Öö Tiib" <ootiib@hot.ee>: Feb 27 12:48PM -0800

On Saturday, 27 February 2016 20:55:54 UTC+2, Marcel Mueller wrote:
> agrument below.
> int Arg; ///< Arbitrary argument to the parser function.
> };
 
I see you use string literals to initialize 'Name' so I don't
understand why there is that mutable array and that L, do you want
to dynamically modify it? String literal is guaranteed to live
forever so you could use pointer to it or pointer and length pair.
 
> int in this example. But this is not safe. Mostly the type is some enum.
> But each function takes another argument type, and of course, the third
> argument in the table must match the argument type of the function.
 
Use some type-safe variant then instead of 'int' for example Boost.Variant,
QVariant, Eggs.Variant.
 
> agrument below.
> P Arg; ///< Arbitrary argument to the parser function.
> };
 
That would not be issue if P was a variant not template argument.
'boost::variant<paramtype1,paramtype2,paramtype3>'. You must know
anyway all the different types of parameters when you initialize
that 'opcodeMap' of yours. Btw words like "Map" and "List" may be
misleading in name of variable since readers sometimes assume
underlying container.
 
> another type P in general and all of these structures must fit into the
> same storage. Of course, there is only a solution when sizeof(P) has an
> upper limit, since this is similar to a union.
 
No ... union is not type-safe, it is type-punning.
 
 
> Could this be expressed type safe in C++11, without the need to deal
> with pointers, new and delete for each line?
 
Unfortunately the 'variant' is not in C++11. The proposal of it
N4542 added default empty state to it while 'boost::variant' has
never-empty guarantee (unless you put 'boost::blank' as first type
that is). Huge language lawyer shitstorm and lot of controversy
later it has transformed into P0088R1 so maybe in C++17 we will have
it.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 27 09:58PM +0100

On 27.02.2016 19:55, Marcel Mueller wrote:
> upper limit, since this is similar to a union.
 
> Could this be expressed type safe in C++11, without the need to deal
> with pointers, new and delete for each line?
 
Easy-peasy.
 
struct Op_entry
{
char const* name;
std::function<void()> parser_func;
};
 
// ... later
Op_entry e{ "Blah!", [=](){ Parser::assembleADD( Inst::A_ADD ); } };
 
Hope I got all the braces matched.
 
Cheers & hth.,
 
- Alf
ram@zedat.fu-berlin.de (Stefan Ram): Feb 27 08:24PM

>>Could this be expressed type safe in C++11, without the need to deal
>>with pointers, new and delete for each line?
>You can declare the array under the scope of a template, e.g.:
 
The code compiled, but I can't read out the actual values.
 
The code commented out in the program below results in
linker errors:
 
#include <initializer_list>
#include <iostream>
#include <ostream>
 
enum class my { A_ADD };
 
template< typename T >struct entry{ int tag; T arg; };
 
::std::ostream & operator<<( ::std::ostream & out, ::my const & v )
{ out << "This is a my value.";
/* if( v == ::my::A_ADD )out << "It is ::my::A_ADD."; */
return out; }
 
::std::ostream & operator<<( ::std::ostream & out, ::entry< ::my >const & v )
{ out << "This is an entry with my enum."; return out; }
 
::std::ostream & operator<<( ::std::ostream & out, ::entry< bool >const & v )
{ out << "This is an entry with a bool."; return out; }
 
template< typename T >const entry< T >array[] ={ { 0, ::my::A_ADD },{ 1, false }};
 
int main()
{ /* ::std::cout << array< ::my >[ 0 ].tag<< '\n'; */
::std::cout << array< ::my >[ 0 ].arg<< '\n'; }
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.

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

alexo <alelvb@inwind.it>: Feb 27 01:38PM +0100

> Where does it fail?
> How does it fail?
> What's it doing at the time?
 
 
The debugger doesn' stops on error. There is not a segfault or similar.
My program simply continues to send data and "hangs".
If I close it with xkill transmission doesn't end. It continues to keep
data transfer to I don't know who.
alexo <alelvb@inwind.it>: Feb 27 01:42PM +0100

> Where does it fail?
> How does it fail?
> What's it doing at the time?
 
 
The debugger doesn't stops on error. There is not a segfault or similar.
My program simply continues to send data and "hangs".
If I close it with xkill data transmission doesn't end.
"Öö Tiib" <ootiib@hot.ee>: Feb 27 05:15AM -0800

On Saturday, 27 February 2016 14:39:24 UTC+2, alexo wrote:
 
Restoring attributions, do not erase those. :(
 
> My program simply continues to send data and "hangs".
> If I close it with xkill transmission doesn't end. It continues to keep
> data transfer to I don't know who.
 
You apparently did not understand what Christopher asked. Possibly you
don't know what debugger is. Debugger is a tool. It does not "debug" on
its own. It helps you to find bugs.
 
Now can you please break the program with debugger and look:
Where does it "hang"?
How does it "hang"?
Why does it "hang"?
What's it doing at the time of "hanging"?
alexo <alelvb@inwind.it>: Feb 27 06:44PM +0100

>> As JiiPee suggested, I've found a very powerful library named curl.
>> The one he suggested, mimetic, has a bug.
 
> Namely?
 
after ./configure
make fails due to errors in the source files
alexo <alelvb@inwind.it>: Feb 27 06:59PM +0100

> How does it "hang"?
> Why does it "hang"?
> What's it doing at the time of "hanging"?
 
This is the source code of the toy program. It is executed correctly
but for the login you obviously have to type in your username password
and smtp server address.
 
when I insert this code in my program,
This code being called by pressing a button on the GUI transmission goes
forever.
the line that fails is this:
 
 
res = curl_easy_perform(curl);
 
 
It starts the transmission of the data and should return.
This is not what happens. The funclion locks the wireless transmission
and after closing the software with xkill, data transmission still
continues, but no mail starts.
 
 
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
OF ANY
* KIND, either express or implied.
*

***************************************************************************/
 
/* <DESC>
* SMTP example showing how to send e-mails
* </DESC>
*/
 
#include <stdio.h>
#include <string.h>
 
#include <time.h>
#include <cstdlib>
 
#include <curl/curl.h>
 
/* This is a simple example showing how to send mail using libcurl's SMTP
* capabilities. For an example of using the multi interface please see
* smtp-multi.c.
*
* Note that this example requires libcurl 7.20.0 or above.
*/
 
#define FROM "<alelvb@inwind.it>"
#define TO "<alessandro.volturno@libero.it>"
//#define CC "<alelvb@inwind.it>"
 
char *current_date();
 
char *date = current_date();
 
static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " /*FROM*/ "Stilottica\r\n",
//"Cc: " CC "Another example User\r\n",
"Subject: ordine lenti\r\n", // subject of tha message
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"Ordine del ", //The body of the message starts here.
// more strings go here
date,
"\r\nA long text email can be very tedious to read."
"\r\n-- end of the message --",
NULL
};
 
struct upload_status {
int lines_read;
};
 
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void
*userp)
{
struct upload_status *upload_ctx = (struct upload_status *)userp;
const char *data;
 
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
 
data = payload_text[upload_ctx->lines_read];
 
if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
upload_ctx->lines_read++;
 
return len;
}
 
return 0;
}
 
int main(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
 
upload_ctx.lines_read = 0;
 
curl = curl_easy_init();
 
/* replace xxx with your credentials */
 
if(curl) {
/* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_USERNAME, "xxxxxxxxx@xxxxxx.xx"); //
curl_easy_setopt(curl, CURLOPT_PASSWORD, "xxxxxxxx");
curl_easy_setopt(curl, CURLOPT_URL, "xxxxxxxx");
 
 
/* Note that this option isn't strictly required, omitting it will
result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be
directed
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for
more
* details.
*/
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
 
/* Add two recipients, in this particular case they correspond to the
* To: and Cc: addressees in the header, but they could be any kind of
* recipient. */
recipients = curl_slist_append(recipients, TO);
//recipients = curl_slist_append(recipients, CC);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
 
/* We're using a callback function to specify the payload (the
headers and
* body of the message). You could just use the CURLOPT_READDATA
option to
* specify a FILE pointer to read from. */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
/* Send the message */
res = curl_easy_perform(curl);
 
/* Check for errors */
 
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else
{
printf("message sent!");
}
 
/* Free the list of recipients */
curl_slist_free_all(recipients);
 
/* curl won't send the QUIT command until you call cleanup, so you
should
* be able to re-use this connection for additional messages (setting
* CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
* curl_easy_perform() again. It may not be a good idea to keep the
* connection open for a very long time though (more than a few minutes
* may result in the server timing out the connection), and you do
want to
* clean up in the end.
*/
curl_easy_cleanup(curl);
}
 
return (int)res;
}
 
char *current_date()
{
time_t rawtime;
struct tm *timeinfo = NULL;
 
char *buf = new char[35];
 
if(buf == NULL)
{
printf("string allocation error\n");
exit(1);
}
 
time(&rawtime);
 
if ((timeinfo = localtime(&rawtime)) == NULL)
{
printf("data generation error");
exit(1);
}
 
sprintf(buf,"%.2d/%.2d/%4d ore %.2d:%.2d",
timeinfo->tm_mday,
1 + timeinfo->tm_mon,
1900 + timeinfo->tm_year,
timeinfo->tm_hour,
timeinfo->tm_min
);
 
return buf;
}
Jorgen Grahn <grahn+nntp@snipabacken.se>: Feb 27 05:59PM

On Fri, 2016-02-26, alexo wrote:
> The one he suggested, mimetic, has a bug.
> I'm an absolute beginner on the field but adapting the example code, I
> was able to send with curl my first email from a C/C++ program.
 
Note that the traditional, safe way of sending an email on Unix is to
pipe it into /usr/lib/sendmail.
 
But perhaps people don't configure this aspect of their Unix systems
properly these days.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
alexo <alelvb@inwind.it>: Feb 27 07:14PM +0100

Il 27/02/2016 13:42, alexo ha scritto:
 
>> Have you made attempts at debugging?
 
yes
 
>> Where does it fail?
 
on the line that starts data transmission namely,
 
res = curl_easy_perform(curl);
 
>> How does it fail?
 
transmission starts and never ends. Even force closing of the program
wireless activity doesn't stop and always stays on, locking internet
communication.
 
 
 
 
 
code of the toy program follows:
in order to make it working you must fill in your username, password and
smtp server address for the outgoing mails.
 
 
here in the code:
 
curl_easy_setopt(curl, CURLOPT_USERNAME, " ");
curl_easy_setopt(curl, CURLOPT_PASSWORD, " ");
curl_easy_setopt(curl, CURLOPT_URL, " ");
 
 
 
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
OF ANY
* KIND, either express or implied.
*
 
***************************************************************************/
 
/* <DESC>
* SMTP example showing how to send e-mails
* </DESC>
*/
 
#include <stdio.h>
#include <string.h>
 
#include <time.h>
#include <cstdlib>
 
#include <curl/curl.h>
 
/* This is a simple example showing how to send mail using libcurl's SMTP
* capabilities. For an example of using the multi interface please see
* smtp-multi.c.
*
* Note that this example requires libcurl 7.20.0 or above.
*/
 
#define FROM "<alelvb@inwind.it>"
#define TO "<alessandro.volturno@libero.it>"
//#define CC "<alelvb@inwind.it>"
 
char *current_date();
 
char *date = current_date();
 
static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " /*FROM*/ "Stilottica\r\n",
//"Cc: " CC "Another example User\r\n",
"Subject: ordine lenti\r\n", // subject of tha message
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"Ordine del ", //The body of the message starts here.
// more strings go here
date,
"\r\nA long text email can be very tedious to read."
"\r\n-- end of the message --",
NULL
};
 
struct upload_status {
int lines_read;
};
 
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void
*userp)
{
struct upload_status *upload_ctx = (struct upload_status *)userp;
const char *data;
 
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
 
data = payload_text[upload_ctx->lines_read];
 
if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
upload_ctx->lines_read++;
 
return len;
}
 
return 0;
}
 
int main(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
 
upload_ctx.lines_read = 0;
 
curl = curl_easy_init();
 
if(curl) {
/* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_USERNAME, " ");
curl_easy_setopt(curl, CURLOPT_PASSWORD, " ");
curl_easy_setopt(curl, CURLOPT_URL, " ");
 
 
/* Note that this option isn't strictly required, omitting it will
result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be
directed
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for
more
* details.
*/
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
 
/* Add two recipients, in this particular case they correspond to the
* To: and Cc: addressees in the header, but they could be any kind of
* recipient. */
recipients = curl_slist_append(recipients, TO);
//recipients = curl_slist_append(recipients, CC);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
 
/* We're using a callback function to specify the payload (the
headers and
* body of the message). You could just use the CURLOPT_READDATA
option to
* specify a FILE pointer to read from. */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
/* Send the message */
res = curl_easy_perform(curl);
 
/* Check for errors */
 
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
else
{
printf("message sent!");
}
 
/* Free the list of recipients */
curl_slist_free_all(recipients);
 
/* curl won't send the QUIT command until you call cleanup, so you
should
* be able to re-use this connection for additional messages (setting
* CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
* curl_easy_perform() again. It may not be a good idea to keep the
* connection open for a very long time though (more than a few minutes
* may result in the server timing out the connection), and you do
want to
* clean up in the end.
*/
curl_easy_cleanup(curl);
}
 
return (int)res;
}
 
char *current_date()
{
time_t rawtime;
struct tm *timeinfo = NULL;
 
char *buf = new char[35];
 
if(buf == NULL)
{
printf("string allocation error\n");
exit(1);
}
 
time(&rawtime);
 
if ((timeinfo = localtime(&rawtime)) == NULL)
{
printf("data generation error");
exit(1);
}
 
sprintf(buf,"%.2d/%.2d/%4d ore %.2d:%.2d",
timeinfo->tm_mday,
1 + timeinfo->tm_mon,
1900 + timeinfo->tm_year,
timeinfo->tm_hour,
timeinfo->tm_min
);
 
return buf;
}
alexo <alelvb@inwind.it>: Feb 27 07:22PM +0100

Il 27/02/2016 19:14, alexo ha scritto:
 
> curl_easy_setopt(curl, CURLOPT_USERNAME, " ");
> curl_easy_setopt(curl, CURLOPT_PASSWORD, " ");
> curl_easy_setopt(curl, CURLOPT_URL, " ");
 
I forgot to specify that it is not the code here reported that fails,
but the same code when I insert it in a callback function to be called
on button pressing.
 
any help is welcome and appreciated
 
thank you
"Öö Tiib" <ootiib@hot.ee>: Feb 27 10:41AM -0800

On Saturday, 27 February 2016 19:59:33 UTC+2, alexo wrote:
> forever.
> the line that fails is this:
 
> res = curl_easy_perform(curl);
 
So your program hangs inside of 'curl_easy_perform' of libcurl.
 
Where does it "hang"?
How does it "hang"?
Why does it "hang"?
What's it doing at the time of "hanging"?
Paavo Helde <myfirstname@osa.pri.ee>: Feb 27 09:46PM +0200

On 27.02.2016 19:59, alexo wrote:
 
> when I insert this code in my program,
> This code being called by pressing a button on the GUI transmission goes
> forever.
 
Obviously your two programs differ in some sense, as one is working as
expected and the other does not. Obviously you have made changes when
pasting the code to your real program (otherwise you would have two
main() functions which would not compile).
 
You have to figure out what is the crucial difference. And no, posting
the code for the *working* program is not very helpful. Instead, you
should extract the minimal *non-working* program from your real app.
 
According to your claims the program is sending infinite amount of data.
However, the data is provided by your own callback function
(payload_source()), so you could easily put a breakpoint there and find
out how much and what data it is sending.
ram@zedat.fu-berlin.de (Stefan Ram): Feb 27 07:36PM

>Could this be expressed type safe in C++11, without the need to deal
>with pointers, new and delete for each line?
 
You can declare the array under the scope of a template, e.g.:
 
#include <initializer_list>
#include <iostream>
#include <ostream>
 
enum class my { A_ADD };
 
template< typename P >struct entry{ P Arg; };
 
::std::ostream & operator<<( ::std::ostream & out, ::entry< ::my >const & v )
{ out << "This is an entry with my enum."; return out; }
 
::std::ostream & operator<<( ::std::ostream & out, ::entry< bool >const & v )
{ out << "This is an entry with a bool."; return out; }
 
template< typename P >const entry< P >array[] ={ { ::my::A_ADD },{ false }};
 
int main()
{ ::std::cout << array< ::my >[ 0 ]<< '\n';
::std::cout << array< bool >[ 1 ]<< '\n'; }
 
This is an entry with my enum.
This is an entry with a bool.
legalize+jeeves@mail.xmission.com (Richard): Feb 27 12:54AM

[Please do not mail me a copy of your followup]
 
Lynn McGuire <lmc@winsim.com> spake the secret code
 
>There is not a standard user interface toolkit proposal.
 
Don't need it.
 
There are already several good defacto standards: Qt, wxWidgets, and
(less to my personal taste, but relevant) MFC. Where "good" is defined
from various perspectives including, but not limited to, freely available,
actively improved, proven viability in the marketplace and portable among
platforms.
 
C doesn't have it.
Python doesn't have it.
JavaScript doesn't have it.
NodeJS doesn't have it.
FORTRAN doesn't have it.
Java doesn't have it.
C# doesn't have it.
 
Why people are insistent on trying to jam every possible library into
the standard is beyond me. Before trying to make the C++ Standard
Library the union of all available libraries on the internet, how
about we sovle the dependency and package system in a reasonable way?
 
Hell, how about we get modules deployed and widely used?
 
Either of those is way more fucking[*] important than a UI library in
the standard.
 
[*] This one's for you, woodbrain77.
--
"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>
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 27 05:19AM +0100

On 27.02.2016 01:54, Richard wrote:
> actively improved, proven viability in the marketplace and portable among
> platforms.
 
> C doesn't have it.
 
Right.
 
> Python doesn't have it.
 
Well, CPython ships with Tk/Inter (I think it was called). Which is
standard in the sense that it's always there, as a basic GUI.
 
 
> JavaScript doesn't have it.
 
Oh, for JavaScript it's just HTML.
 
 
> NodeJS doesn't have it.
 
An embarrassment of riches. First of course basic HTML, both on the web,
in web apps (including Android phone apps), and e.g. Windows HTML
applications (old but still going technology). But then also the two
variants of whatever it was called, that was used to build the editor,
that the Microsoft "Code" editor is based on (and still uses that).
 
Sorry I'm not more clear on this. I could research it. In fact that's
the plan, but I'm not there yet. :(
 
 
> FORTRAN doesn't have it.
> Java doesn't have it.
 
Well, at first Java had AWT, and then Swing built on AWT. At which
point, as I recall, they changed the namespaces, breaking lots and lots
of code. Infuriating.
 
 
> C# doesn't have it.
 
C# is like NodeJS, just too many GUI toolkits now. But the main basic C#
GUI stuff is Windows Forms. I believe Mono has Windows Forms support?
 
 
> Library the union of all available libraries on the internet, how
> about we sovle the dependency and package system in a reasonable way?
 
> Hell, how about we get modules deployed and widely used?
 
Good ideas all, I agree.
 
And there is already experimental support for modules in Visual C++.
 
Which reminds me to try that out! :)
 
But I think that one should start at the absolutely first little thing
that one needs to deal with to do C++ programming. And that is of course
the `main` function. Happily Microsoft recently informed me they'll fix
their lack of direct support for standard `main` in GUI subsystem
programs, in some forthcoming release. Well, at least I chose to
interpret the wording that way. But [1]judge for yourself. :)
 
Then, I think it would be nice to get basic type support in place, in
particular character encoding value types and ditto string literals, as
in my work-in-progress [2]cppx library, or thereabouts. Well not just
international text handling support, but also, hm, dates!, and a decimal
type sufficient for handling national scale monetary amounts, and,
little things like getting -- for Pete's sake -- [3]a `std::pi` constant!
 
It's all the little stuff that makes the language usable.
 
Having each project and person reinvent the wheel again and again and
again, is IMHO sub-optimal. Well the Poco library does some of this. But
for some reason I've never used Poco -- have any reader?
 
 
> Either of those is way more [expletive removed] important than a UI
> library in the standard.
 
Yes I agree. :)
 
 
Cheers!,
 
- Alf
 
 
Notes:
[1] <url:
https://connect.microsoft.com/VisualStudio/feedback/details/2128262/missing-c-11-standard-macro-stdc-hosted>
[2] <url: http://alf-p-steinbach.github.io/cppx/>
[3] `M_PI` is already de facto standard, but not part of the C++
standard. It surprised me, once, to realize how much innovation the
committee's been doing, while /not/ standardizing widely used existing
practice. Anyway, more info: <url:
http://stackoverflow.com/questions/1727881/how-to-use-the-pi-constant-in-c>
David Brown <david.brown@hesbynett.no>: Feb 27 02:41PM +0100

On 27/02/16 05:19, Alf P. Steinbach wrote:
 
>> Hell, how about we get modules deployed and widely used?
 
> Good ideas all, I agree.
 
> And there is already experimental support for modules in Visual C++.
 
Unfortunately, I think they are significantly different from the
experimental modules in clang. I wish they would get this one sorted
out, so that we can have a single proper module feature for C++.
"Öö Tiib" <ootiib@hot.ee>: Feb 27 08:45AM -0800

On Saturday, 27 February 2016 15:41:31 UTC+2, David Brown wrote:
 
> Unfortunately, I think they are significantly different from the
> experimental modules in clang. I wish they would get this one sorted
> out, so that we can have a single proper module feature for C++.
 
Experimental implementation is not carved into rock and its makers
knew that it has to be likely rewritten. People who used such for
real product knew with what they risk.
 
I am more worried that adding innovations like Modules, Concepts and
Reflection at once will cause serious headache of integrating those
features into whole.
Dombo <dombo@disposable.invalid>: Feb 27 07:41PM +0100

Op 27-Feb-16 om 5:19 schreef Alf P. Steinbach:
>> from various perspectives including, but not limited to, freely
>> available, actively improved, proven viability in the marketplace and portable among
>> platforms.
 
Unfortunately those user interface kits are showing their age; they
don't take advantage of modern C++ features but instead choose to supply
their own string, container...etc classes and mechanisms. All of this
was understandable in the nineties before C++ was standardized but is
unforgivable in this day and age.
 
It would be nice to have a multi platform widely used GUI toolkit that
takes advantage of modern C++ and that smoothly interfaces with the
standard library.
 
[snip]
>> C# doesn't have it.
 
> C# is like NodeJS, just too many GUI toolkits now. But the main basic C#
> GUI stuff is Windows Forms. I believe Mono has Windows Forms support?
 
Development of WinForms has stopped well over a decade ago, nowadays WPF
is pretty much the way to go. Besides those two I don't know of any
other widely used GUI toolkit in the .NET world.
"Öö Tiib" <ootiib@hot.ee>: Feb 27 11:23AM -0800

On Saturday, 27 February 2016 20:41:05 UTC+2, Dombo wrote:
> their own string, container...etc classes and mechanisms. All of this
> was understandable in the nineties before C++ was standardized but is
> unforgivable in this day and age.
 
It is actually good. It makes clear interface where your program logic
layer (that does not use UI classes) touches with UI (that does not
use standard library).
 
Standard C++ has weak and full of "implementation-defined" features
regarding unicode, locales etc. This day and age we have to either:
a) accept having files with names full of garbage, show different
garbage instead of text on each platform and also format numbers
(nothing to talk of money, date and time) in unpredictable way;
b) write significant amount of portability code to deal with it;
c) use platform-specific API calls;
d) use those QStrings and QLocales that already deal with it.
 
 
> It would be nice to have a multi platform widely used GUI toolkit that
> takes advantage of modern C++ and that smoothly interfaces with the
> standard library.
 
I like harshly interfacing GUI. I dislike code where program logic is
intermixed with GUI and I congratulate GUI toolkit that makes it as
painful as possible for those who let so different responsibilities
to diffuse all over the code base.
Marcel Mueller <news.5.maazl@spamgourmet.org>: Feb 27 07:55PM +0100

Let's have a dispatch table of an assembler.
 
 
/// Entry of the OP code lookup table, POD, compatible with binary_search().
/// @tparam L maximum length of Name.
template <size_t L>
struct opEntry
{ char Name[L]; ///< OP code name
void (Parser::*Func)(int);///< Parser function to call, receives the
agrument below.
int Arg; ///< Arbitrary argument to the parser function.
};
 
/// Map with opcode tokens, must be ordered.
const Parser::opEntry<8> Parser::opcodeMap[] =
{ {"add", &Parser::assembleADD, Inst::A_ADD }
, {"and", &Parser::assembleADD, Inst::A_AND }
, {"asr", &Parser::assembleADD, Inst::A_ASR }
, {"bpkt", &Parser::assembleSIG, Inst::S_BREAK }
, {"bra", &Parser::assembleBRANCH, false }
//...
};
 
 
Each parser function takes an (optional) argument. The type is fixed to
int in this example. But this is not safe. Mostly the type is some enum.
But each function takes another argument type, and of course, the third
argument in the table must match the argument type of the function.
 
For type safe operation it would be nice to have a type like
 
 
template <size_t L, typename P>
struct opEntry
{ char Name[L]; ///< OP code name
void (Parser::*Func)(P);///< Parser function to call, receives the
agrument below.
P Arg; ///< Arbitrary argument to the parser function.
};
 
 
But this does not work since each line of Parser::opcodeMap[] has
another type P in general and all of these structures must fit into the
same storage. Of course, there is only a solution when sizeof(P) has an
upper limit, since this is similar to a union.
 
Could this be expressed type safe in C++11, without the need to deal
with pointers, new and delete for each line?
 
 
Marcel
Les Cargill <lcargill99@comcast.com>: Feb 26 07:07PM -0600

David Brown wrote:
>> 'C' so you have to test it.
 
> No, endianness is not remotely "undefined behaviour" - it is
> /implementation/ defined behaviour. There is a huge difference.
 
Ah, there you go. Right! I'd forgotten the term of art.
 
<snip>
 
--
Les Cargill
Allan Herriman <allanherriman@hotmail.com>: Feb 27 08:58AM

On Fri, 26 Feb 2016 17:09:37 +0100, David Brown wrote:
 
> compiler - so it is not going to happen. (I know of only one case where
> this happened - and that was on MS's x86 compiler, a long time ago,
> where they changed the bitfield endianness.)
 
It happened to me on an 8051 C compiler in the '90s. The endianness of
bitfields changed between one compiler version and the next.
I learned a lesson, and have not used bitfields in C since then.
 
I believe the compiler vendor is still in business today (well, they were
bought by a microcontroller manufacturer).
 
Regards,
Allan
David Brown <david.brown@hesbynett.no>: Feb 27 02:37PM +0100

On 27/02/16 09:58, Allan Herriman wrote:
>> where they changed the bitfield endianness.)
 
> It happened to me on an 8051 C compiler in the '90s. The endianness of
> bitfields changed between one compiler version and the next.
 
Thanks - now I know of /two/ cases where compilers have changed bit
ordering!
 
> I learned a lesson, and have not used bitfields in C since then.
 
You are throwing out the baby with the bathwater. If you avoid using a
feature just because a small-time compiler writer for a brain-dead and
C-unfriendly processor made an inconvenient decision two decades ago,
you would have to give up programming altogether. Bitfields have
portability issues, but can be extremely useful - they are perfectly
safe to use once you understand them.
 
"Öö Tiib" <ootiib@hot.ee>: Feb 27 07:21AM -0800

On Saturday, 27 February 2016 15:37:59 UTC+2, David Brown wrote:
> you would have to give up programming altogether. Bitfields have
> portability issues, but can be extremely useful - they are perfectly
> safe to use once you understand them.
 
+1. Not only small-time. All the versions of "big-time" compilers have
been defective in one or other way. There are only (more or less)
defective tools and libraries and platforms. Getting the work done
with such is part of skill. Without desire to acquire that skill it
is impossible to make software.
David Brown <david.brown@hesbynett.no>: Feb 27 04:34PM +0100

On 27/02/16 16:21, 嘱 Tiib wrote:
> defective tools and libraries and platforms. Getting the work done
> with such is part of skill. Without desire to acquire that skill it
> is impossible to make software.
 
Changing the bitfield order between versions is not really a "defect" as
such - it's a design decision, not a bug. When MS did it (and I guess
they count as "big-time"), they moved to little-endian ordering because
it was much more common for other tools on the x86 and other
little-endian processors. So it was a good decision, but it came as a
surprise to people who had upgrade compiler versions and found their
code changed functionality.
 
But yes, even "big-time" compilers have bugs. Some, like gcc and clang,
are very open about them - some others prefer to keep them secret until
you open a support case (I don't mean to imply that all closed-source
compiler manufacturers keep their bugs secret, as that would be far from
true). It seems there is little relationship between the cost of tools
and their quality. Certainly the last compiler bugs I have seen have
been in very expensive, big-name tools for a brain-dead microcontroller.
Those bugs turned up on simple, clear code - nothing complicated or
bleeding-edge. (I would prefer not to name the tools as I have only
helped out another developer here, rather than studying the tool in detail.)
"Öö Tiib" <ootiib@hot.ee>: Feb 27 10:14AM -0800

On Saturday, 27 February 2016 17:35:00 UTC+2, David Brown wrote:
> little-endian processors. So it was a good decision, but it came as a
> surprise to people who had upgrade compiler versions and found their
> code changed functionality.
 
I meant it more generally. People who ever want to port their code to
different version or different compiler or different platform should
be prepared that there are some noisy and some silent breaking changes.
Some are because of implementation-defined features like that binary
representation of bitfield some are because of defects. Defects are
most likely in the code compiled but sometimes also in previous or
new implementation.
 
> Those bugs turned up on simple, clear code - nothing complicated or
> bleeding-edge. (I would prefer not to name the tools as I have only
> helped out another developer here, rather than studying the tool in detail.)
 
Such things happen rarely may be 1-3 times a year but I have also feeling
that if a tool costs like $2K or more per license then it is a warning
sign about potential quality issues.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Feb 27 05:53PM

On Fri, 2016-02-26, Haddock wrote:
> wanted to ask whether anybody out there working in this domain could
> give me a hint what to work on to get more into C++. What I thought
> of was writing a parser to parse CSV files or XML.
 
Both are good exercises (except just /parsing/ is not useful in
itself), but are you sure that's close to what you'd do in that
domain?
 
> Write something that generates optimized C++ code to parse
> something. But I'm not sure whether that's something good.
 
Write code which generates C++ source code? Not that interesting,
IMHO, especially since TMP is so trendy.
 
> Any ideas greatly appreciated.
 
Investigate more. I don't know anyone in that domain and never worked
there, so I don't know what they focus on. Could be almost anything.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
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.