Sunday, December 18, 2022

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

Roman P <invalid@example.com>: Dec 18 08:00PM

1) What happens when you divide an int variable by 0?
2) What happens when you divide a double variable by 0?
3) What happens when you overflow an int variable, that is, set it to a
value beyond its range?
4) What is the difference between x = y++; and x = ++y;?
5) What is the difference between break, continue, and return when used
inside a loop statement?
6) What are the three parts of a for statement and which of them are
required?
7) What is the difference between the = and == operators?
8) Does the following statement compile?
 
for ( ; ; ) ;
 
9) What does the underscore _ represent in a switch expression?
 
Merry Christmas to you all.
Ben Bacarisse <ben.usenet@bsb.me.uk>: Dec 18 09:22PM

Roman P <invalid@example.com> writes:
 
I now see that this is cross-posted to comp.lang.c++ as well as to
comp.lang.c. That's not a good idea for quizzes like this.
 
> 1) What happens when you divide an int variable by 0?
 
Asking what "happens" in this sort of context is a bit odd, but maybe
clarifying what this might mean is part of the question?
 
> 2) What happens when you divide a double variable by 0?
> 3) What happens when you overflow an int variable, that is, set it to a
> value beyond its range?
 
And here there is even more ambiguity since a variable (what might
better be called a named object) can be set in two ways, and the C
standard says different things about each!
 
> inside a loop statement?
> 6) What are the three parts of a for statement and which of them are
> required?
 
The correct answer for C was made more complicated in 1999, and as for
C++, well that's a whole new ball game.
 
> 8) Does the following statement compile?
 
> for ( ; ; ) ;
 
> 9) What does the underscore _ represent in a switch expression?
 
There is no switch expression in C and a switch statement can include
lots of expressions. But, that aside, I'd like to see what you think
the answer is.
 
> Merry Christmas to you all.
 
And to you too.
 
--
Ben.
red floyd <no.spam.here@its.invalid>: Dec 18 01:36PM -0800

On 12/18/2022 12:00 PM, Roman P wrote:
> 8) Does the following statement compile?
 
> for ( ; ; ) ;
 
> 9) What does the underscore _ represent in a switch expression?
 
Do your own homework.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Dec 18 01:48PM -0800

On 12/18/2022 12:00 PM, Roman P wrote:
> 1) What happens when you divide an int variable by 0?
[...]
 
Undefined behavior.
Siri Cruise <chine.bleu@yahoo.com>: Dec 18 02:57PM -0800

In article <tno1qh$21o4$2@dont-email.me>,
> > 1) What happens when you divide an int variable by 0?
> [...]
 
> Undefined behavior.
 
https://www.youtube.com/watch?v=JOiZP8FS5Ww
 
Saved by zero.
 
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Chen sockpuppet. insults Islam. Mohammed
"daniel...@gmail.com" <danielaparker@gmail.com>: Dec 18 03:18PM -0800

On Sunday, December 18, 2022 at 3:22:18 PM UTC-5, Roman P wrote:
> 1) What happens
 
Also of interest, what happens when you write code that calls substr on a
std::basic_string<char,std::char_traits<char>,MyAllocator> when the template parameter
MyAllocator is a stateful allocator?
Pawel Por <porparek@gmail.com>: Dec 18 02:13AM -0800

Hello,
 
I'd like to understand the implementation of std::initializer_list constructor. I've copied the most recent std::lib implementation from git and building it with gcc 9.4.0 -std=c++2a. I get the following error:
 
error: no matching function for call to 'custom_initializer<int>::custom_initializer(<brace-enclosed initializer list>)'
 
I don't understand what is the basic mechanism to pass the brace-enclosed list to the constructor.
Please give me some hints.
Thank you in advance
 
template<class _E>
class custom_initializer
{
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
 
private:
iterator _M_array;
size_type _M_len;
 
// The compiler can call a private constructor.
constexpr custom_initializer(const_iterator __a, size_type __l)
: _M_array(__a), _M_len(__l) { }
 
public:
constexpr custom_initializer() noexcept
: _M_array(0), _M_len(0) { }
 
// Number of elements.
constexpr size_type
size() const noexcept { return _M_len; }
 
// First element.
constexpr const_iterator
begin() const noexcept { return _M_array; }
 
// One past the last element.
constexpr const_iterator
end() const noexcept { return begin() + size(); }
};
 
int main(int argc, char **argv)
{
custom_initializer<int> ppp{1, 2, 3};
return 0;
}
Bo Persson <bo@bo-persson.se>: Dec 18 12:33PM +0100

On 2022-12-18 at 11:13, Pawel Por wrote:
> custom_initializer<int> ppp{1, 2, 3};
> return 0;
> }
 
std::initializer_list is "magic" in that the compiler knows about it and
its connection to brace initializers.
 
Your class lacks this compiler magic, so works differently (=not supported).
Pawel Por <porparek@gmail.com>: Dec 18 12:40PM -0800

> std::initializer_list is "magic" in that the compiler knows about it and
> its connection to brace initializers.
 
> Your class lacks this compiler magic, so works differently (=not supported).
 
Thank you for response. Is this "magic" somehow available for the users or totally hidden. If so, how can I use it ?
Albert Arkwright <Albert.Arkwright@gmail.com>: Dec 18 01:25AM

On 17/12/2022 20:47, Mr Flibble wrote:
> We need to accelerate investment in new nuclear build and green hydrogen
> technologies to counter climate change.
 
There is a better alternative and the waste product degrades pretty
quickly. It's called Nuclear Fusion:
 
<https://youtu.be/d0OSLz9i5p8>
Mr Flibble <flibble@reddwarf.jmc.corp>: Dec 18 06:46AM

On Sun, 18 Dec 2022 01:25:00 +0000, Albert Arkwright wrote:
 
 
> There is a better alternative and the waste product degrades pretty
> quickly. It's called Nuclear Fusion:
 
> <https://youtu.be/d0OSLz9i5p8>
 
Nuclear fusion outside of the lab is still decades away, if we ignore the
Sun and thermonuclear weapons of course. :)
 
/Flibble
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Dec 17 10:56PM -0800

On 12/17/2022 12:47 PM, Mr Flibble wrote:
> exists and creating more of it doesn't make the problem significantly
> worse or have any bearing on solving that problem. Just my two cents.
> #climatecrisis #ClimateEmergency
 
Bob Lazar's hydrogen Corvette from years ago:
 
https://youtu.be/Ytg23mDd1a4
 
We need the metal hydride to store the hydrogen.
scott@slp53.sl.home (Scott Lurndal): Dec 18 05:17PM

>exists and creating more of it doesn't make the problem significantly
>worse or have any bearing on solving that problem. Just my two cents.
>#climatecrisis #ClimateEmergency
 
Even if we were able to build enough fusion power plants (if they ever
become viable) to replace the current fossil based energy supplies,
(before fossil fuels run out, or there won't be enough energy to
build the replacement facilities[*]) there is a hard limit on the amount
that energy consumption can grow (at the current rate of growth
the waste heat alone from power production and use will heat the
planet surface to the boiling point of water within four centuries;
with habitability eliminated in two centuries - and that's ignoring
carbon dioxide emissions based warming completely).
 
https://dothemath.ucsd.edu/2011/07/galactic-scale-energy/
 
[*] https://dothemath.ucsd.edu/2011/10/the-energy-trap/
 
Here's an open-source textbook that goes into the physics of energy
production and consumption. Pretty bleak.
 
https://escholarship.org/uc/energy_ambitions
scott@slp53.sl.home (Scott Lurndal): Dec 18 05:28PM


>Bob Lazar's hydrogen Corvette from years ago:
 
>https://youtu.be/Ytg23mDd1a4
 
>We need the metal hydride to store the hydrogen.
 
From one of the comments on one of the lazar videos:
 
Pretty cool stuff. Using a lithium hydride for storage
is a huge improvement over pressurized/liquified hydrogen
for storage and transport.
 
The drawback is efficiency; it takes a lot more energy to
separate the hydrogen from oxygen in water than you get back
by burning the hydrogen. If you take the electricity used to
separate the hydrogen, and store it in a lithium ion battery
(for example) you can use an electric motor to run the car
directly with 80-90% efficiency, and you don't need a particle
accelerator to generate the hydride (particle accelerators use
a lot of electricity). The hydrogen powered vehicle only captures
about 30% of the electrical energy used to capture the hydrogen
and manufacture the hydride as fuel energy for the vehicle. The
same electricity used to generate 400 miles of hydrogen range
would give you 900 miles of battery range if you used it to simply
charge up a Tesla. The hydrogen-powered car does give you more
energy-dense fuel storage: the hydride tanks for 400 miles of fuel
weigh much less than a 400-mile range lithium-ion battery (a Model
S with a 100 kWH battery pack has a 403 mile range, for example). The
hydride vehicle is cool, and green, but all-electric battery-operated
vehicles are more than twice as efficient, which means they cost half
as much to run in kiloWatts per mile. Who killed the hydrogen car?
Economics, in the form of cheap lithium ion batteries and efficient
electric motors."
-Steven Gulie
 
 
Boeing and Airbus, realizing that their business models are at risk, given
worldwide goals on reduction of CO2 emissions (a bit more than 2% of CO2
emissions are for air passenger and freight traffic) have been investigating
several possible alternatives, including SAF (Sustainable Aviation Fuel, such
as that made from recycled fats or from agricultural waste feedstocks),
Hydrogen (Liquified or Pressurized H2 Gas either combustion or fuel cell),
Electric (Battery in the 1000 to 2000km range basket) or a recent suggestion
from WPI, a Magnesium Hydride slurry added to JET-A, the Mg binds to CO2
in the atmosphere and precipitates out as MgCO3 or MG(CO3)2; harmless
(and actually edible) capture of the Carbon from the atmosphere making
the flight carbon-negative. It does still rely on a non-renewable
resource, and the energy costs of creating the MH2 slurry may be prohibitive.
Lynn McGuire <lynnmcguire5@gmail.com>: Dec 18 01:19PM -0600

On 12/18/2022 11:17 AM, Scott Lurndal wrote:
 
> Here's an open-source textbook that goes into the physics of energy
> production and consumption. Pretty bleak.
 
> https://escholarship.org/uc/energy_ambitions
 
Hot tubs for everyone !
 
Lynn
Lynn McGuire <lynnmcguire5@gmail.com>: Dec 17 07:13PM -0600


> Though I suppose it begs the question of why americans feel the need to drive
> around in absurdly large utility vehicles. Insecurity perhaps or maybe posing.
> But thats an argument for another newsgroup.
 
Merika !
 
Lynn
Lynn McGuire <lynnmcguire5@gmail.com>: Dec 17 07:20PM -0600

On 12/17/2022 4:27 AM, Chris M. Thomasson wrote:
>> posing.
>> But thats an argument for another newsgroup.
 
> Ever had to tow a big boat before?
 
I tow a 5,000 lb 35 foot boom lift two or three times a year. I also
manage to get myself in a foot or two of mud and water occasionally.
Dadgum feral hogs.
 
Lynn
scott@slp53.sl.home (Scott Lurndal): Dec 18 05:37PM


>> Something that perhaps 15% of non-commercial pickup truck owners actually do.
 
>Towing a boat up and down to Lake Tahoe from Carson City, one needs a
>vehicle than can do it.
 
 
That covers about 0.005% of all large pickup drivers., but doesn't answer
the question posed above. That stretch of Highway 50 isn't typical,
even in california or nevada (hopefully your're not taking 207).
 
I drive that stretch of 50 annually during my labor day Yosemite-
Lee Vining/Mono Lake-Tahoe journey (although every couple years, I'll
take 89 or 207 from 395 just for a change of scenery).
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: