Hacker News new | past | comments | ask | show | jobs | submit | RicardoLuis0's comments login

that's the altered part -- those more restrictive terms of the VVVVVV license only apply to the _assets_, and the license for the source code itself is far more liberal:

https://github.com/analgesicproductions/Even-The-Ocean-Open-...


if your data's sequential, creating an iterator in C++ is as simple as returning a begin and end pointer, and will be optimized away by any level other than O0

https://godbolt.org/z/WEjzEr5j4


But iterating over pointers is once again optimized with lots of undefined behavior at the corners. So you are replacing one source of undefined behavior with another.


Replacing undefined behavior at the program-level with undefined behavior written and tested as part of the standard library, usually vendored and distributed in concert with the compiler, seems like an obvious net-positive to me.


Pointer arithmetic optimization based on undefined behavior is a problem regardless.

Life is always better after minimizing the total number of types of undefined behavior.


> with lots of undefined behavior at the corners.

What behavior is undefined in incrementing a pointer between a begin and end range?


Of course a basic iteration between begin()/end() will never contain out of range elements, but neither will valid increment between two integers. No need for iterators in that case either.

Say I want to do something fancy, like getting element number 11 from an array.

With an integer index I can pass 11, with random access iterators I can use begin() + 11.

Now my array only has five elements. So I check.

11 < 5? Comparison valid, successfully avoided a crash.

begin() + 11 < end() ? How where the rules for pointer comparison again, something about within an allocation and one past the end?


> something about within an allocation and one past the end?

Yeah, I forgot about that. So I agree there is some subtly which is likely to catch beginners.

Your example could safely be:

   if (std::distance(begin, end) > 5) 
Another approach I would recommend is to write a `guarded_advance` which takes an integer and the end pointer.

Also note that the situation you are describing is still a little unusual because the baseline assumption is it takes linear time to advance an iterator by more than 1 increment.

> but neither will valid increment between two integers. No need for iterators in that case either.

The purpose of an iterator is to abstract data structure access. The coordinate inside a complex data structure may not be representable by an integer.


> So why aren't we doing this?

isn't IPv6 is basically that? just restricted to internet addresses


It's sort of this. Although it would've been nice if the size of the IP wasn't restricted, so one day we can add an optional segment on top and connect the whole Milky Way, or something.


Fun fact: a ping from the center to the extreme of the milky way would overflow for 64 bit millisecond timestamps.


and it's not like SRAM isn't used in modern computers -- it's baked directly into the silicon of your CPU to serve as register banks and cache


> the case of a run-away string

that, i'd guess, is one of the reasons why most languages don't allow multi-line strings without special syntax


It's definitely why TeX macros are not "\long" (i.e. they cannot span more than one paragraph) by default.


it seems to be on github, but the commit history doesn't go beyond 2017: https://github.com/beejjorgensen/bgc


that one in particular was not really caused by goto, but rather by braceless if statements, it'd be a vulnerability all the same if the line was a "fail" function that was called instead of a goto.


just about any electronics here in brazil are ~2x the price, be it phones, computers, computer parts (CPUs, GPUs, MOBOs, etc), or anything else (not just apple, any brand)


This is true. When the PS5 was launched, the prices in Brazil were (they still are but that's beside the point) ridiculously high.

Gamers complained, in an incredibly amateurish PR stnt Sony decided to launch a campaign justifying the high prices on taxes.

Obviously, people decided to calculate this. Even taking the PS5's RRP in the US or Europe (as opposed to cost) and applying Brazilian taxes on top, the final figures were still around 40% lower than what they were charging.


> applying Brazilian taxes on top, the final figures were still around 40% lower than what they were charging

So taxes are only part of the explantion. Who do you suppose is responsible for the rest of the much higher prices? Are Sony and Apple pricing their products way higher for Brazil? Is it the importers? Or are the retailers simply charging what the Brazilian market will bear?

It should be possible for some enterprising Brazilians to import Sony and Apple products from elsewhere in the world, pay the Brazilian taxes, and still sell for less than the current retailers, which would eventually bring down the prices. I can't understand why that doesn't happen.


> Who do you suppose is responsible for the rest of the much higher prices?

In the case of Apple, they sell them directly so I don't think it's anyone but themselves. Not sure about Sony and others.

> Or are the retailers simply charging what the Brazilian market will bear?

This is certainly a factor. Similarly, cars are way overpriced in Brazil, simply because people will pay.

> It should be possible for some enterprising Brazilians to import Sony and Apple products from elsewhere in the world

They do, but usually small scale. I know people who have purchased Apple computers for half the Brazilian price from sellers on Mercado Livre (South American eBay).


it's not guaranteed atomic, and if you ARE using volatiles, "maybe" doesn't really cut it, so now you need to do `++*v` the proper way (ex. `lock cmpxchg` / `__atomic_compare_exchange`), or explicitly write it out the long way (`*v = *v + 1`) and risk the small chance of the value changing under you between read/write


that's still wrong, the integer data model is defined by the target, which is not specified in the quiz, not solely by the compiler, ex. clang uses 32-bit longs when compiling for windows, and 64-bit longs when compiling for linux:

* windows - https://godbolt.org/z/WWWzarEsK

* linux - https://godbolt.org/z/57WK45o6e

same for gcc on linux/windows (mingw)


Are there any GCC or LLVM targets where short is the same size as int?


Motorola 68K target with -mshort option.


Any 8 or 16 bit micro controllers like the AVR.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: