This is one of the major cause of the destruction of the environment we're seeing globally.
All forecasts predict another 60% (!!) increase in global population before it stabilises.
Forget about banning plastic straws or flying less (which are feel-good measures more than anything else) with such numbers... We need to take dramatic and effective steps.
There are 80 years left until the end of the century. This increase is far from being inevitable! But, again, we prefer to ignore these key issues and focus on marginal, feel-good measures instead.
This increase is essentially unavoidable at this point in time. It happens despite the fact that fertile couples now only reproduce at replacement rate. But older smaller generations get replaced by larger younger generations. There is a multi decadal lag in population dynamics.
Why forget about the easiest steps if we need dramatic ones?
Why should rich people continue to fly around the world while you try implementing big restrictions on everyone? This makes no sense.
Perhaps you meant "In addition to bans on (...), we need dramatic measures"? Also, suggesting some steps would help understand how stronger your proposals are.
People are flying around the world trying to figure out how to supply people like you solar pannels, wind turbines and batteries. Enviomental solutions require a suppy chain, R & D and new factories.
Perhaps you didn't read the article, because its main point is that the official UN forecast is for world population to essentially flatten out at 10.9B around 2100, which is 40% more than today, not 60%.
Correction: we don't want to manage now. The world has far more than enough wealth and resources to hold climate change to 2 degrees and to stop clear cutting rain forests.
We can and do manage now, thank you very much. Poverty is decreasing at an incredible rate around the globe; education is increasing at an incredible rate. We've made the world's knowledge available to virtually everyone via in the internet just in the time I've been an adult. We've eradicated diseases that once killed millions every year.
Two thirds of the global extreme poverty (defined by the World Bank as about $1.80/day in current dollars) has been eradicated in just the past two decades.
We also have about ten years of carbon budget left if we want to avoid the worst climate change yet our emission rate is still increasing. Permafrost is already melting much faster than the pessimistic models assumed, so it might already be too late to prevent the release of the absurd amount of carbon locked in the ice.
I expect to see fossil fuel use as a major energy source eradicated within my lifetime. The planet is just fine; it's our own living environment we need to worry about. Earth has survived worse things than mere humans.
As a point of comparison, the global population has almost quadrupled in the previous 80 years. So even in the worst case scenario, population growth is dropping spectacularly.
It's only an international affair because the Chinese government has gone full paranoid and blame other countries because their people didn't like the bill.
Anyway, massive demonstrations are usually newsworthy, like the Yellow Vests in France until a few months ago.
When people are used to this they can't easily tell what is satire anymore.
I remember a few years back China Daily (or was it the People's Daily) quoted The Onion because the 'journalist' hadn't realised it was a satirical website...
Modern compilers do have insight into the source before it was preprocessed. You'll notice that clang and (modern) gcc will show you where the error is in the unexpanded source line, and then show the expansion of the macros. So when it detects "2^32", it can look back to see if it was a product of macro expansion or if the literal was directly written, and warn accordingly.
Interestingly, msvc can also do this, by virtue of not even having a distinct preprocessor phase at all.
I don't think it would not be simple or a good idea to warn because these are perfectly valid expressions and it would lead to a flood of warnings if compilers started to display "Did you really mean that?" for an ever growing list of expressions (which is what it would become).
Better to leave this to code analysis tools.
Edit:
2^32 uses the ^ operator exactly as intended, and has perfectly legitimate uses, especially when dealing with registers of HW peripherals.
It's not the same as warning on "if (a=b)" as someone replied.
From a language perspective, 2^32 is exactly the same as 2+32.
It's a warning not an error. Moreover, it is very hard to come up with a legitimate usecase of 2^32 as an expression. People who use it to set bit flags will use &, and for bit flags, octal or hex notation is probably better.
I don't know if it is a good practice, but I often have statements and expressions that look awfully similar. Flipping bits does happen often enough.
Mostly written as y ^ (1 << x), which could easily resolve to these expressions. Mostly at runtime, sure, but there are exceptions. Especially if you like descriptive constants. I would expect it to be quite difficult to separate the "correct cases" without people starting to just suppress compiler warnings or trick it with writing the same stuff in different words (which might be better).
On the other hand, setting max_short to something like 18 is probably a really god prank in larger programming environments. The compiler would just ruin all the fun here.
> Mostly written as y ^ (1 << x), which could easily resolve to these expressions.
We’re talking about a parse-time check; things that resolve to those values after identifier binding won’t throw the warning. It’s not a warning about what you wrote (semantically), it’s a warning about how you wrote it (syntactically).
I would agree with the suggestion then. It can happen that you just write it out like that and the compiler should maybe inform me. But why limit it to 2^ and 10^ and not say literal^literal should always produce a warning? Any common or valid usages that I am missing here?
Certainly, I'd say if either side is a hex or octal literal, it might be someone intentionally bit-twideling.
As for limiting the base, that is a more fluid matter. I guess you want to avoid warnings for very large numbers. Because those are more likely legitimate.
Many build environments are set to treat all warnings as errors.
The point is that 2^32 is a perfectly compliant C expression that is neither misleading nor ambiguous, and that also won't create any variable overflow. It uses ^ exactly as intended. Why should the compiler complain? Why should I get a warning/error when following the spec to the letter?
Like it or not, there are already tons of lint-like warnings in GCC [1] and clang [2]. Many (uh, most?) of them are not required by the C/C++ standards (which by the way have their own requirements for diagnostic messages).
Plenty of valid expressions generate warnings. A frequent gotcha is `=` in boolean contexts. Warnings are justified, and can normally be avoided with a little bit more lexical work (e.g. an extra set of parentheses). The upside is large and the downside is miniscule.
Isn't that pretty much the definition of a warning? An expression that is technically valid, but probably a mistake. If something wasn't a valid expression, it would be a compiler error, not a warning.
Usually, yes. C is weird because undefined behavior is illegal, can sometimes be detected statically, and yet will not produce an error. So sometimes you get warnings for invalid yet error-free code. It’s a strange language.
Environments where the decision has been made that error-prone, misleading and ambiguous statements should not be allowed typically are those where warning are treated as errors.
A new type of misleading and error-prone statement has been found, so it seems entirely reasonable that this is added to that list.
This seems to be the entire intent of compiler warnings (these days anyway)
Heuristics like this are important because humans are not machines. If you run into a warning in one of these situations, they are usually rectified by changing the statement slightly. Worst case scenario you can #pragma push and pop the warning.
> It's not the same as warning on "if (a=b)" as someone replied.
"if (a=b)" uses the "=" operator exactly as intended with perfectly legitimate uses. It's warned about because it's an error-prone construct, not because it's incorrect.
Seems to me 2^32 is also error-prone, if you wanted to combine flags you'd use 2|32, using xor here is weird.
'If' expects a condition so finding an assignment may be a red flag even if an assignment has a return value in the spec, which makes the construct valid.
On the other hand ^ expects integers so 2^32 is exactly what is expected.
Most the replies I saw here try to second-guess or claim that ^ should be used in a specific way. Not so, ^ is just doing XOR of two integers.
Apparently, I am having an incorrect opinion, though, so I will self-censor and remain silent.
You don't have to enable warnings, but most c programmers do.
The problem is, what proportion of 2^32 in C are correct? I'm will to bet it is as close to 0 as doesn't matter. The gcc devs aren't stupid, before enabling a warning like this, they will run a test compiling a substasal chunk of debian, and see if there are any false positives.
> I don't think it would not be simple or a good idea to warn because these are perfectly valid expressions and it would lead to a flood of warnings if compilers started to display "Did you really mean that?" for an ever growing list of expressions (which is what it would become).
There are many technically valid expressions and statements that will still generate warnings in most compilers.
I'm intrigued at what your opinion is about the following Rust errors:
error[E0308]: mismatched types
--> src/main.rs:4:8
|
4 | if x = y { println!("eq") }
| ^^^^^
| |
| expected bool, found ()
| help: try comparing for equality: `x == y`
|
= note: expected type `bool`
found type `()`
error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison
--> src/main.rs:4:17
|
4 | if i as u32 < 2 {
| -------- ^ --- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the cast value: `(i as u32)`
test.c:7:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
if (c)
^~
test.c:9:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
exit(0);
^~~~
"2^32" is of course just an xor, but it makes no sense (the "exclusive" part of it is not being exercised). If you really mean 2 bits being set in a constant then "2 | 32" is much clearer. If you're dead set on xor, "32^2" won't trigger the warning.
It's not for you or the compiler to decide that 2^32 makes no sense. It is using ^ exactly as intended and is neither misleading nor ambiguous.
Stating that 32^2 should not trigger a warning while 2^32 should shows that this proposal has not been thought through.
It's not desirable or sensible to raise a warning on the premise that the expression might mean something else in another language, which is what this would do.
I feel perfectly qualified to say that 2^32 makes no sense.
Just because something is specced doesn't mean that it's reasonable. My "if statement" example is perfectly valid C, but it's not reasonable. 2^32 is perfectly valid, but also unreasonable. Frankly, any bitwise operations with >10 decimal constants are either intentionally obfuscating, or done by someone who doesn't know what they are doing. Consider "2^32" vs "0x02^0x20". The latter is much better.
It is entirely sensible to warn on the premise that it might mean something in another language: The construct seems to be an actual point of confusion (the authors sited numerous real code examples where people are accidentally doing this in the wild), and the construct makes no sense at face value. I think you'd be hard pressed to find a real example of 2^32 in code where it isn't a bug. That's enough to make it a reasonable warning.
All forecasts predict another 60% (!!) increase in global population before it stabilises.
Forget about banning plastic straws or flying less (which are feel-good measures more than anything else) with such numbers... We need to take dramatic and effective steps.
There are 80 years left until the end of the century. This increase is far from being inevitable! But, again, we prefer to ignore these key issues and focus on marginal, feel-good measures instead.