Hacker Newsnew | past | comments | ask | show | jobs | submit | blorsh's commentslogin

No, type punning via unions is a gcc extension.

The standard only allows reading a value as the type it was written with or as char, and an access as char is only good for copying. If a char access used different bit order, that would be OK according to the standard because you couldn't tell unless you violated the standard.

It seems every compiler will tolerate a memcpy for type punning, even though this isn't required.


C99 and C11 allow type punning via unions (although apparently that only gets mentioned in a footnote)

https://stackoverflow.com/questions/11639947/


Does this mean that memcpy() is really more of a language construct than a library function, since it cannot be implemented correctly in fully defined standard C?


Yes. Check here for a discussion: https://blog.regehr.org/archives/959


Everything defined in the standard is in principle a language construct: whether it is builtin in the compiler or an actual function is an implementation detail. For many compilers, memcpy is both: they have builtin handling for it but fall back to the library implementation when there is no optimization opportunities.

Having said that, it is possible to implement memcopy in standard C: char pointers have an explicit special exemption to the aliasing rule so you are allowed to inspect objects as array of chars.


memcpy is legal and fine. To borrow the example from above:

  double d = 3.14;
  uint64_t i;
  memcpy(&i, &d, sizeof(d));
is perfectly kosher.


> is perfectly kosher

Aren't exact-bitwidth integer types optional even with C99 (let alone preceding versions of standard)?


They are optional, but only in the sense that if you can't exactly represent e.g. uint64_t, there can't be a uint64_t type. So the example above is kosher in the sense that it's standards compliant, even if it isn't perfectly portable (for reasons unrelated to memset type punning; that you're using uint64_t in the first place).

If an implementation can't represent uint64_t exactly, it can still have a uint_least64_t type of whatever width works.


I certainly agree with what you said as you said it. However, as usual, it is the implementation that kills it.

a) I believe sizeof (double) * 8 == 64 is not enforced by the standard either. One could argue that it is hard to find anything else these days, but (for a contrived example) I believe nothing prevents you from making your own port of GCC for some purpose, and make 'double' be 'float'. (From my memories, it is even far enough from rocket science.)

b) It already happened to me personally, to work with code where people have implemented their own uintXX types (because of the lack of the standard ones), and then over time these became narrower/vider.

So if we would like to have it portable, I think, nothing beats:

union { double d; char cc [sizeof (double)]; };

and there we are, back to what is in the standard.


I mostly agree, but with b) IMO the problem was that you worked in an environment that was already not concerned with the standard. I'm not sure if it's OK by the standard for a user to define types named e.g. int32_t that don't comply to the standard restrictions.

sizeof (double) can be guaranteed to be 8 if __STDC_IEC_559__ is defined, so checking that is an additional hurdle if you want to use memcpy for punning. That said, I think it can be assumed that you're writing non-portable code for a specific set of platforms already if you are punning floats to integers, because the representation is implementation dependent in the first place. Probably you also know the environments in which it will be compiled as well, so the example is a bit contrived.

Very much agree that unions are the easiest and standard way to do type punning. There's so many misconceptions about this somehow being unclear in the standard. Sure, it does reflect poorly on the quality of the standard that Linux contributors don't understand it and that Linus Torvalds actively ignores it, but if you know what you're looking for it's often not that hard to find a definite answer.


Assuming brain changes only, more like:

looks like a chimpanzee, can't really talk due to throat limitations, can't walk very well, but likes to read and write


What would be interesting is if a humanzee turns out perhaps to be just as intelligent and perhaps fitter than humans due to hybrid vigor? Nobody really knows how intelligent a humanzee might bee.


I see his chimp hybrid and raise him from hominid to hominin. The Homo sapiens neanderthalensis genome is complete enough by now that we could arguably do the same thing with a Neanderthal man.

I think that could well be more informative to mankind's understanding of itself, and likely to cause less suffering for the created individuals.

Not that I particularly agree that either is a good idea.


Attempting to clone a Neanderthal hybrid (because there is no Neanderthal mother anymore so epigenetic is wrong) would probably be a better idea. Should tell us more about their capabilities.

They should also be relatively possible to integrate into society. As opposed to uplifted chimpanzee.


The only real solution to gerrymandering is to use a minimally-complicated algorithm.

The algorithm need not actually determine the districts. It can instead simply rate proposals, allowing a contest to be held. The highest scoring proposal submitted at least 400 days prior to the election is the winner, with earlier submissions winning any ties.

Another improvement would be to let districts spill over state borders. One could exempt Alaska and Hawaii of course.


Or you could just do away with it all and go for a one man one vote system. Why a vote in Kansas needs to be tallied differently from a vote in New York in the 2020 elections is beyond me.


Districts don't matter for the presidential election. They only affect apportionment in the House of Representatives, which is region based and is 1 man 1 vote (within state boundaries. Even across states the differences in voting power isn't as aggregious as the Senate or overall electoral college).


> Districts don't matter for the presidential election.

Except in Maine and Nebraska (selection of Presidential electors is largely a matter of state law, and most but not all states are winner take all.)


Like many features of the original constitution, protecting slavery (the slave states were modtly low population states, with even smaller voting populations, and were particularly concerned that equal representation would eventually turn against them—abolitionism was already a thing at the time of the Constitution, and they were very concerned about it taking hold) was a major concern. The representation structure (and it's special protection against revision by amendment) plus the 3/5 compromise plus the explicit, limit term, protection of the slave trade, among other provisions of the Constitution, were protection against that eventuality.


Because presidential elections are not popular elections. Kansas has proportional representation in the House but is absurdly over-represented in the Senate and slightly over-represented in the Presidency.

This is of course by design. The founder's obviously knew about proportional representation and they deliberately chose to disregard it. Shouldn't that give you pause to figure out why?


> The founder's obviously knew about proportional representation and they deliberately chose to disregard it. Shouldn't that give you pause to figure out why?

Turns out the reason was slavery. A huge proportion of the Southern population was enslaved, and slaves didn't vote. The free staters didn't want slaves to even count toward state population for the purposes of congressional apportionment, while the slave staters did, so they compromised on counting the slave population at 3/5 of the free population. As a result, prior to the abolition of slavery, the votes of free men in slave states were always represented at a higher proportion than the votes of free men in free states.

Many of the founders were wise and educated men who thought carefully and critically about how to establish a sustainable republic. But to do so, they had to win the votes of a cross-section of the American establishment of the time, many of whom thought that owning human beings, using them as farm labor, and whipping them if they disobeyed were morally acceptable things to do. And upon making a series of political compromises with these people, they had to rationalize those compromises in such a way to make them palatable to the general public.


Most of them were perfectly fine with owning people.


A lot them even owned their own slaves.


Indeed. With our current system, rural voices are at least marginally relevant. With a purely proportional system, rural voices would not even be heard.


The major reason is that smaller states wouldn't have joined any proposed Union that made them irrelevant, so the founders had to have things like the Senate to get them to join at all.

This is, of course, no longer relevant.


If it’s no longer relevant, it should be possible to convince small states both red & blue to accept an obviously superior system.

But it is still relevant for just about all the reasons it was relevant then.


I think if you had some way of forcing the issue, and telling states like Kansas and Mississippi that they didn't get to have disproportional control over the federal government anymore, and if they didn't like it, they could just stop being subsidized by California and New York, either they would go along with it, or they would secede from the union and deteriorate into third world countries.


Why would states persist in a union that made them irrelevant? The politics are still as relevant today as it was then.


It’s way harder to leave than it was to refrain from joining.

Another major factor is that Americans mostly see themselves as citizens of the USA first, and citizens of their state a distant second.


Because the alternative is worse.


They also didn't choose to tie electors to the per state popular vote and chose the electoral college in part to prevent the election of terrible candidates.


>Why a vote in Kansas needs to be tallied differently from a vote in New York in the 2020 elections is beyond me.

    population of Kansas (state):  2.9 million
    population of New York (city): 8.5 million
Without some sort of balancing mechanism, you wind up with a single populous city's votes mattering more than the votes from every city in a less populous state.


What is wrong with that, exactly? If the city is substantially larger than the state, it seems reasonable to me that its votes would matter more.


This is something our founders debated. It's never good to let the whims of the majority trample on the minority. It's why we have both the house of representatives (based on population) and the senate (flat number per state).

If little states have no say in our government, what point is there for them to remain?

It's a pity some folks devalue others simply because they don't wish to live in NYC or LA.


> It's never good to let the whims of the majority trample on the minority

You are arguing for the minority to trample on the majority.


That’s not what I’m arguing.

It needs to be competitive. The majority shouldn’t be able to have its way without the help of the minority.


Why is the rural minority so special? We don’t give other minorities this sort of treatment.

For example, the percentage of rural Americans is similar to the percentage of black Americans. Yet somehow nobody ever argues that black Americans need power disproportionate to their numbers to avoid being trampled.


> Why is the rural minority so special?

It's not about rural vs urban. It's about the assumption that the US is a union of separate _states_ with separate legal structures, cultures, etc, etc. So it's not the "rural minority" that's special; it's states that are special.

Now you may disagree with the premises there, of course. But if one accepts the premises, then one needs a way to prevent "big" states from just imposing their will on "small" ones.

(There are in fact people who argue that black Americans need disproportionate power, and some voting districts are set up to effectively produce that, but that has nothing to do with the setup of the US constitution per se.)


They called out NYC and LA so I don’t think they were thinking along the same lines you are.

Of course you need this if one accepts the premise that states are special. You’re basically just assuming the conclusion at that point.

I’m not aware of any voting district that’s set up to give black Americans a disproportionately large amount of power. There are some that are deliberately set up to ensure proportionate power.


I called out NYC and LA because they’re high population areas.

My point is this: delegating power to solely the majority is a bad idea, full stop. In a properly functioning society, the majority needs to work cooperatively with the minority, which means the minority needs some sort of functional advantage (like we have in the US Senate, with respect to states).

How individual states set up this power balance internally is up to them. Obviously I think it should follow a similar model to the one we have at the federal level with our collection of states.

It annoys me when people rag on smaller areas like RI or WY because they get “extra privileges” or some such nonsense when it comes to elections or the US congress.


This seems to assume that there is some fixed “the minority” that needs to be advantaged in order to be fair, and further that “the minority” corresponds to the smaller states.

In reality, there’s a different minority for every issue. Giving states with low population a disproportionate amount of power doesn’t necessarily balance the minority with the majority. Depending on the issue it may allow the majority to more easily trample the minority, or it may allow a minority to impose its will on the rest.

The solution to requiring cooperation with the minority is to require more than a simple majority to do things. See for example: removal following impeachment, constitutional amendment, treaty ratification, or the de facto situation in the Senate for most legislation at the moment.


We're a federal republic made up of 50 states plus DC. Balancing the power between _states_ is standard among federal republics (Germany, Switzerland, Argentina, Brazil, Mexico, ...).

Federal republics _need_ the power balance among _states_, otherwise there's no point in the states participating in the republic, thus no point in even having a federal republic. If that's your point, fine. But you can't have your cake and eat it too.

How states want to balance out things internally is up to them, and that can be used to help the minority on specific issues.


A federal structure is a means to an end, not the goal itself. If it doesn’t serve the purpose we want then we should change it.

In any case, even if you take the state as the unit that needs to be balanced, my point stands: you can’t balance “the minority” by picking some arbitrary minority and giving them more power.


I can see an argument either way. More populated areas to legitimately represent commercial and cultural centers, but also, the needs of the entire system have to be considered.


What is it about rural voters that make them more important to the entire system?


Resources.


Yes, which is how it should be.

States have senators to prevent tyranny of the majority. NYC should be worth more house seats than all of Kansas.


Without some sort of rebalancing mechanism, you wind up with a singe empty state's votes mattering more than every voter in a city.


The mechanism you're talking about is the federal government.


I found the comment to be insightful. I'm trying to find his violation, and I can't really. There are a few things that are close, maybe, but not really.

"political or ideological battle" and "shallow dismissals" seem most plausible, but neither really fits. It's not as if the entirety of his comment was "more dumb leftist shit". There was more substance to his comment.

???


It's a shallow dismissal. It makes a grandiose claim without support. More importantly, it doesn't teach us anything. An example or two could have rectified that.


Do I need to provide an example that water is wet? But ok, just for you:

Largest scale:

USSR North Korea Cuba Recent entry: Venezuela Recent entry: South Africa

Smaller:

https://www.economist.com/news/business/21589469-collapse-sp...

Even smaller:

https://munchies.vice.com/en_us/article/gvkqnm/marxist-vegan...


Maybe an example or two wouldn't have rectified it. Would you please read the site guidelines and abide by them when commenting here?

https://news.ycombinator.com/newsguidelines.html


Ah, but why were there children and old people being murdered en masse?

It's because humans naturally resist what was being imposed upon them. The smart and able-bodied are going to get more, and they will resist any effort to prevent this. Corruption and workplace theft were rampant in the Soviet Union.

Suppression of this resistance requires violence.


IDA Pro is far more usable, particularly for heavy-duty long-term users. There is a bit of a learning curve, but IDA Pro has a really efficient interface. You get the beauty and readability and nice flowchart-like layout that can be done in a GUI, while the keyboard control has efficiency like a well-made DOS or mainframe program.


The politician pays the union. The union pays the politician.

So both are getting paid, out of money taken by force from the population. Neither has an interest in making this stop.

About the only hope is that 1-sided political donations will sufficiently tick off a political party at the national level. There is a tiny chance that national law could change because of that.


You also have two parties, the "government" and the "opposition". They are created after the election. At that point, the voters no longer get any say. The voters don't even know what they will get.

Consider a situation that starts with 12 parties. One gets 45% support, and the others each get 5% support. When the 12 parties merge into the 2 that will actually govern, that party with 45% may be the loser. The other 11 can merge to become a party with 55% of the power. The party which is most popular by far is thus locked out of power.


Ultrasound does damage brain tissue.

It has been studied in China, where evidently it was considered ethical to do so. Search terms: China ultrasound study

What this does to the population's average mental ability and sanity is an interesting question. Autism is suspected.


Numerous states had already sued the Obama administration in the other direction. (DACA being unlawful in the first place) Due to those still-ongoing lawsuits, DACA was probably about to go down in flames already.


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

Search: