Monday, January 18, 2016

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

Juha Nieminen <nospam@thanks.invalid>: Jan 18 09:59AM

> I just read a web page »Almost Always Auto« and wanted
> to give it a try.
 
I'd suggest the exact opposite principle: Almost never auto.
 
Strong typing is one of the advantages of C++, as it catches mistakes
at compile time (which is one of the best stages at which to catch
mistakes). If you have something like:
 
MyType result = foo();
 
and it turns out that foo() doesn't actually return a value that's
compatible with MyType, the compiler will immediately tell you. If you
used auto, the error message would much more obscure, and in a few cases
it could even compile but malfunction, which would be the worst possible
scenario (and something that's avoided by not using 'auto').
 
That's not to say that 'auto' is useless. On the contrary. It's extremely
useful. It's very useful in generic code, especially templated code.
 
It's also useful in non-generic code, but should be used there only when
it makes sense to use it. In general, in non-generic code it should/can be
used when it really is so that the actual type doesn't matter. This may be
in cases where the code just doesn't care what the type is, or when there
is some guarantee about the behavior of the type, but the exact name of the
type is irrelevant (iterators are a perfect example.)
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Wouter van Ooijen <wouter@voti.nl>: Jan 18 06:55PM +0100

Op 18-Jan-16 om 10:59 AM schreef Juha Nieminen:
> used auto, the error message would much more obscure, and in a few cases
> it could even compile but malfunction, which would be the worst possible
> scenario (and something that's avoided by not using 'auto').
 
OTOH, if foo() returns something that can be converted to a MyType yours
statement will do so silently, which I dislike.
 
> That's not to say that 'auto' is useless. On the contrary. It's extremely
> useful. It's very useful in generic code, especially templated code.
 
IMO auto is usefull in almost all code. When your code silently
malfunctions because the thing that foo() returns is not what you
expected but still has the same methods/signatures there is something
seriously wrong.
 
> in cases where the code just doesn't care what the type is, or when there
> is some guarantee about the behavior of the type, but the exact name of the
> type is irrelevant (iterators are a perfect example.)
 
IMO nearly all code is an example of what you describe. The only reason
for *not* using auto is that you defintely need a specific type, which
should be rare.
 
Wouter van Ooijen
Paavo Helde <myfirstname@osa.pri.ee>: Jan 18 09:02PM +0200

On 18.01.2016 19:55, Wouter van Ooijen wrote:
> Op 18-Jan-16 om 10:59 AM schreef Juha Nieminen:
>> I'd suggest the exact opposite principle: Almost never auto.
> IMO auto is usefull in almost all code.
 
auto should be used if it makes the code more readable and more
understandable as the alternatives, and vice versa. It's as simple as that.
 
Cheers
Paavo
scott@slp53.sl.home (Scott Lurndal): Jan 18 07:03PM


>IMO nearly all code is an example of what you describe. The only reason
>for *not* using auto is that you defintely need a specific type, which
>should be rare.
 
Actually, it's not rare at all in embedded programming, systems programming and in programming
simulations of physical processors and other hardware elements to require
a type with specific size and alignment characteristics.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jan 18 07:12PM

On Mon, 2016-01-18, Juha Nieminen wrote:
>> I just read a web page »Almost Always Auto« and wanted
>> to give it a try.
 
> I'd suggest the exact opposite principle: Almost never auto.
 
Isn't it funny -- and sad -- how an obviously useful feature such as
this one opens up a can of worms?
 
I probably use 'auto' more than you do at this point, but I can easily
imagine a future where some people write code which others (like me)
reject as unreadable. As if we're not our own worst enemies already ...
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Wouter van Ooijen <wouter@voti.nl>: Jan 18 10:50PM +0100

Op 18-Jan-16 om 8:03 PM schreef Scott Lurndal:
 
> Actually, it's not rare at all in embedded programming, systems programming and in programming
> simulations of physical processors and other hardware elements to require
> a type with specific size and alignment characteristics.
 
It embedded it is very common to have hardware registers of specific
size and address, but you won't find them defined and at the same moment
initialized from some expressing. In embedded too, it is very likely
that you want to store the result of an expression in a variable of the
appropriate type, that is: the type of the expression.
 
There are of course plenty exceptions. For instance,
 
for( auto i = 0; i < 200; i++ )...
 
is not a wise line to write when you are (also) targeting 8-bit chips,
that can handle an byte much more efficient yet have '0' as (16-bit)
int. More appropropriate is
 
for( uint_fast8_t i = 0; ....
 
Or even better: some way to select the index type automatically based on
the upper limit.
 
Wouter van Ooijen
Vir Campestris <vir.campestris@invalid.invalid>: Jan 18 09:54PM

On 18/01/2016 17:55, Wouter van Ooijen wrote:
> OTOH, if foo() returns something that can be converted to a MyType yours
> statement will do so silently, which I dislike.
 
I use auto when I have to, and only then.
 
If foo returns something that can be converted to a MyType I'll probably
have done it on purpose. If I store foo in an auto, then later try to
stuff that in an STL type I'm into template error message madness - and
not at the point of the call to foo.
 
Andy
"Öö Tiib" <ootiib@hot.ee>: Jan 18 02:04PM -0800

On Monday, 18 January 2016 21:12:42 UTC+2, Jorgen Grahn wrote:
 
> I probably use 'auto' more than you do at this point, but I can easily
> imagine a future where some people write code which others (like me)
> reject as unreadable. As if we're not our own worst enemies already ...
 
It is art like any other. If I feel a need to hover mouse over auto
variable to find out what its type is then it apparently slows down my
reading of code. On the other hand if there is stutter like that then
it is annoying:
 
std::shared_ptr<IconicNode> iconicNode = std::make_shared<IconicNode>();
legalize+jeeves@mail.xmission.com (Richard): Jan 18 06:00PM

[Please do not mail me a copy of your followup]
 
no@notvalid.com spake the secret code
 
>What is essentially better in wxWidgets compared to MFC?
 
As with Qt, the essential difference is that wxWidgets/Qt applications
are portable to operating systems other than Windows.
 
>but Qt is not free, is it? there are a lot of people who would not pay .
 
Qt is free. You can purchase a commercial license to obtain other
benefits, but it is not required.
 
>> YMMV, of course.
 
>obviously if you need multiplatform stuff, then right tool needs to be
>there. but like me am doing only windows programming currently.
 
Right. However, I would categorize you with the legacy code folks
that I mentioned. You invested in learning MFC so you want to
leverage that investment going forward.
 
My intent was not to open up the "MFC vs. other GUI frameworks"
debate, but to simply point out that there are many people programming
for Windows only that don't know or care about MFC for whatever
reason. For a long time the reason was that it wasn't freely available.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
legalize+jeeves@mail.xmission.com (Richard): Jan 18 06:02PM

[Please do not mail me a copy of your followup]
 
Vir Campestris <vir.campestris@invalid.invalid> spake the secret code
 
>I like to toss my code at different compilers purely because they have
>different error checking.
 
This is the point I was trying to make; sorry if that wasn't clear in
my earlier post on this thread.
 
>I've had the pain of upgrading a major code base just from one version
>of MSVC to another. As it turned out all the things it moaned about were
>worth fixing.
 
I've had a similar experience; everything whined about by various
compilers (and most things pointed out by static analyzers) were worth
fixing.
--
"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>
JiiPee <no@notvalid.com>: Jan 18 07:03PM

On 18/01/2016 18:00, Richard wrote:
 
>> What is essentially better in wxWidgets compared to MFC?
> As with Qt, the essential difference is that wxWidgets/Qt applications
> are portable to operating systems other than Windows.
 
ok, but what if somebody does only code for Windows?
 
 
>> but Qt is not free, is it? there are a lot of people who would not pay .
> Qt is free.
 
i understood its not totally free, but I guess you know....
 
> Right. However, I would categorize you with the legacy code folks
> that I mentioned. You invested in learning MFC so you want to
> leverage that investment going forward.
 
So far my clients have actually all used MFC, so good for me. And yes,
thats how I see it. But I dont work for big companies...
 
> debate, but to simply point out that there are many people programming
> for Windows only that don't know or care about MFC for whatever
> reason. For a long time the reason was that it wasn't freely available.
 
yes for me also. I was using wxWidgets before just becouse of this. Well
I had VS2008 full version, but I did not want to start buying every
second year expensive new version. Luckyly somebody here mentioned its
free now, so jumped back to MFC ;).
 
I wonder if the VC2015 community remains free forever... there must be
some catch here?? It sounds too good to be true.
JiiPee <no@notvalid.com>: Jan 18 07:06PM

On 18/01/2016 18:00, Richard wrote:
 
>> What is essentially better in wxWidgets compared to MFC?
> As with Qt, the essential difference is that wxWidgets/Qt applications
> are portable to operating systems other than Windows.
 
But I really like the VS interface.... all the debugging and other stuff
they work nice and just like I want them to work.
But seems to me that GCC compiler is better... maybe need to google if
its possible to nicely use VS with GCC compiler, hopefully its possible,
then could do DOS type of programs with GCC and windows with MFC.
legalize+jeeves@mail.xmission.com (Richard): Jan 18 08:18PM

[Please do not mail me a copy of your followup]
 
no@notvalid.com spake the secret code
>> As with Qt, the essential difference is that wxWidgets/Qt applications
>> are portable to operating systems other than Windows.
 
>ok, but what if somebody does only code for Windows?
 
As mentioned earlier, even if you were programming Windows only
Qt/wxWidgets had the advantage of being free and open source. MFC is
now freely available, but it is still not open source. To some folks
that is an important difference.
 
>>> but Qt is not free, is it? there are a lot of people who would not pay .
>> Qt is free.
 
>i understood its not totally free, but I guess you know....
 
You can use the LGPL license or the commercial license. Rather than
trying to restate what Qt already says, I will simply point you at
their page that describes all this: <http://www.qt.io/FAQ/>
 
LGPL generally means that you can link against it without open
sourcing your application. (Which is why RMS hates the LGPL.)
<https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License>
 
>So far my clients have actually all used MFC, so good for me. And yes,
>thats how I see it. But I dont work for big companies...
 
Yes, there are *huge* amounts of MFC based applications out there. It
isn't going away anytime soon.
 
>I wonder if the VC2015 community remains free forever... there must be
>some catch here?? It sounds too good to be true.
 
As an MVP for 10 years I got to know how things operate within
Microsoft pretty well. The Visual Studio team and their products are
not considered a revenue producing product like Office, SQL Server or
Windows 10. Visual Studio is about developer mindshare to make it
nice and/or easy to develop applications for Windows. To the extent
that they charge anything for various bits of Visual Studio they weigh
that against the pressure it puts against it to decrease developer
mindshare because free trumps any price for many developers when it
comes to tooling.
 
Making MFC freely available means it is easier for more people to make
MFC based applications. That encourages more MFC based applications,
which is good for Windows as a platform.
 
So from that perspective, I wouldn't worry about MFC/ATL being taken away
as a free option now that they've made it available in Community
edition. To me it signals a competitive response in the "platform
wars" in that they think making MFC/ATL freely available encourages
more people to develop for Windows.
--
"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>
Bo Persson <bop@gmb.dk>: Jan 18 09:28PM +0100

On 2016-01-18 21:18, Richard wrote:
> Qt/wxWidgets had the advantage of being free and open source. MFC is
> now freely available, but it is still not open source. To some folks
> that is an important difference.
 
For some definition of "open source". :-)
 
The source IS provided with the compiler, but of course you are not
allowed to create your own branch.
 
 
Bo Persson
legalize+jeeves@mail.xmission.com (Richard): Jan 18 08:55PM

[Please do not mail me a copy of your followup]
 
Bo Persson <bop@gmb.dk> spake the secret code
>> now freely available, but it is still not open source. To some folks
>> that is an important difference.
 
>For some definition of "open source". :-)
 
I'll use the Open Source Initiative's definition:
<http://opensource.org/osd>
 
MFC doesn't qualify as open source.
--
"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>
Cholo Lennon <chololennon@hotmail.com>: Jan 18 06:08PM -0300

On 01/18/2016 05:18 PM, Richard wrote:
> Making MFC freely available means it is easier for more people to make
> MFC based applications. That encourages more MFC based applications,
> which is good for Windows as a platform.
 
I thought MFC was dead (at least it was declared in that way several
times after 2000). In advance of that "dead", I switched my developments
to WTL in 2003. In 2005 I changed my domain to multi platform server
programming. After that I've never touched MFC code again.
 
Regards
 
--
Cholo Lennon
Bs.As.
ARG
Vir Campestris <vir.campestris@invalid.invalid>: Jan 18 09:56PM

On 18/01/2016 19:03, JiiPee wrote:
 
> I wonder if the VC2015 community remains free forever... there must be
> some catch here?? It sounds too good to be true.
 
The catch is your apps will only run on Windows, and you'll have learnt
to become a Windows programmer.
 
Andy
red floyd <no.spam@its.invalid>: Jan 18 12:44PM -0800

On 1/17/2016 6:49 AM, Öö Tiib wrote:
> sequence or relation between objects or types. Otherwise it can
> become pointless and simple text is more comprehensive to most
> people.
 
Wind River VxWorks 6 could actually debug code at the UML level.
It was a pain in the ass, and you had to use their toolset, but
it was doable.
Juha Nieminen <nospam@thanks.invalid>: Jan 18 09:48AM

> You're right of course. Although Stefan Ram /does/ have a point: if
> you say "STL", sooner or later someone is going to try to correct you.
 
> I personally avoid the word for that reason.
 
The standard library is quite large. The template classes and functions
there are a quite important and fundamental sub-section of it, and it
makes sense to refer to those in many contexts. How should you refer
to them if "STL" is forbidden?
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jan 18 06:49PM

On Mon, 2016-01-18, Juha Nieminen wrote:
> there are a quite important and fundamental sub-section of it, and it
> makes sense to refer to those in many contexts. How should you refer
> to them if "STL" is forbidden?
 
I never said "forbidden" -- I just said I avoid it in order to avoid
boring controversies about the name.
 
I find that I rarely have to talk about the STL part of the library:
it's there, it's the most interesting part, and I today can take it
for granted that people know and use it. I try to ignore the few who
don't.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Daniel <danielaparker@gmail.com>: Jan 18 11:03AM -0800

On Monday, January 18, 2016 at 1:50:17 PM UTC-5, Jorgen Grahn wrote:
 
> I find that I rarely have to talk about the STL part of the library:
> it's there ... people know and use it. I try to ignore the few who don't.
 
Interesting. If I ignored the ones who don't, just about my entire social circle would be gone.
 
Daniel
Jorgen Grahn <grahn+nntp@snipabacken.se>: Jan 18 08:34PM

On Mon, 2016-01-18, Daniel wrote:
>> it's there ... people know and use it. I try to ignore the few who don't.
 
> Interesting. If I ignored the ones who don't, just about my entire
> social circle would be gone.
 
Sorry; I meant on Usenet. In real life, C programmers (for example)
are just as fascinating as whoever agrees with me on the right way to
use C++11. Some of them even like cats ...
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Yang Luo <youngluoyang@gmail.com>: Jan 18 05:33AM -0800

I use dos command "net", need administrator privilage.Now I need put this command into c++ code, I use system() function, like this 'system("net
use S: \\computername\foldername");', So how can I improve dos command excute privilage while running c++ code.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 18 02:53PM +0100

On 1/18/2016 2:33 PM, Yang Luo wrote:
> this command into c++ code, I use system() function, like this
> 'system("net use S: \\computername\foldername");', So how can I
> improve dos command excute privilage while running c++ code.
 
 
There are two main ways for you, assuming (as the question indicates)
that you don't want to have your C++ program running elevated.
 
First, you can create a shortcut that provides elevation. That's all you
need directly, but for completeness I mention that you can use that to
provide a batch file "run elevated" command, to some degree like
Unix-land "sudo". In order to run a shortcut via the C++ `system`
function, I think you can just specify its full name, with ".lnk"
filename extension. For some inexplicable reason the ".lnk" extension is
not in the PATHEXT list, which means that by default you cannot omit the
extension.
 
Second, from the C++ code you can use the Windows API function
ShellExecute, with "runas" argument.
 
There is also a third way to run code elevated, which is a bit advanced,
namely using a COM interface that's used by ShellExecute internally.
 
But I'd go for the simple shortcut, which as it happens is a
programming-language-agnostic solution.
 
 
Cheers & hth.,
 
- Alf
 
PS: A question like this is much better asked in a Windows-specific
group, at least wrt. the goal of keeping the groups clean & useful.
There is a little bit of C++ relevance in the question, e.g. it mentions
C++. But mostly and primarily this is about Windows, independent of
programming language, i.e. OFF TOPIC in this group.
Juha Nieminen <nospam@thanks.invalid>: Jan 18 10:13AM

> In function 'int main()':
> 9 29 [Warning] the address of 'int f()' will always evaluate as 'true' [-Waddress]
 
> Let me test this!
 
You don't understand what the compiler's message is saying. It's saying that
"*here* the address always evaluates to true". In other words, where the address
is being used at that line.
 
If you change the line, then it might not just evaluate to 'true' anymore.
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: