Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Fri Jan 08, 2016 9:05 pm UTC

You could go with `optional<T> x(emplace);` after writing `optional<T>`. ;)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
chridd
Has a vermicelli title
Posts: 761
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Sat Jan 09, 2016 12:54 am UTC

EvanED wrote:Maybe this is religious wars, but I'll put it here for now...

Goddammit C++ can be a terrible language sometimes. Some of this anger is directed at the fact that we're not using C++11 for some reason, but most of it C++98/03 deserves.

Code: Select all

template<typename T>
void foo() {
    // declare and value-initialize 'x' of type 'T'
}


How do you do it?

You can't, not without jumping through lots of hoops.
What about this?

Code: Select all

#include <iostream>

template <class T>
struct Initialized {
public:
   T value;
   Initialized() : value() {}
};

template <typename T>
void foo() {
   Initialized<T> x;
   // ...do something with x.value (use x.value instead of x); for example:
   std::cout << x.value << std::endl;
}

// ...test program...
// test class with default constructor but no visible copy constructor
class Test_class {
public:
   Test_class() {std::cout << "Test_class() called" << std::endl;}
private:
   Test_class(const Test_class&) {std::cout << "Test_class copy constructor" << std::endl;}
};

std::ostream& operator<<(std::ostream& out, const Test_class&) {
   out << "Test_class output" << std::endl;
   return out;
}

int main() {
   foo<int>();
   foo<double>();
   foo<Test_class>();
}
Not pretty, but it should work, and doesn't require a copy constructor.
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · they (for now, at least) · Forum game scores
mittfh wrote:I wish this post was very quotable...
flicky1991 wrote:In both cases the quote is "I'm being quoted too much!"

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jan 11, 2016 3:22 pm UTC

Code: Select all

inline void f() {
  std::function<void()> bob = [](){/* do nothing lambda */};
}

The above, if included in two different cpp files, makes programs ill formed, no diagnostic required.

Fuck.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 11, 2016 6:16 pm UTC

Why does that happen? The ODR rule does not apply to inline functions or template instantiations. Does it apply to lambdas? Or does something unrelated happen?

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Jan 11, 2016 6:31 pm UTC

ODR applies to bodies of inline functions.

All calls must resolve to the same overload, unless the function was defined within the scope of the inline function (like a lambda ctor).

The lambda in two different inline functions (in two different cpp files that is: each copy of an inline function is different in a sense) have different names.

So the overload of then std::function ctor called is different: identical in practice, but actually takes a different lambda.

We have overload resolution returning a different result: ODR violation. We can even see it happen by returning the typeid of the object stored in the std function: depending on optimization settings, you can get different values (!).

Probably a standard defect, but a doozy to fix.
Last edited by Yakk on Mon Jan 11, 2016 7:20 pm UTC, edited 1 time in total.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 11, 2016 7:12 pm UTC

Ouch, that sounds nasty to fix.

OTOH does this really happen in practice? If I'm not mistaken at least the Itanium ABI prevents this. Both inline functions get the same (mangled) name and one of them will be discarded during linking. The compiler may still emit the second lambda function but that will be a local symbol so it will never be reached from other object files.

However it cannot prevent really nasty stuff like returning the lambda (or a derived expression) per value (in C++14, I don't think that's possible in C++11), taking its decltype (to leak the lambda out of the function without calling it) and then taking its type info.

EDIT: Actually it can as the lambda will be placed in the same COMDAT section as the inline function and will be discarded when the inline function is discarded. The mangled name of both lambdas is equal (which is not a problem because they are local symbols, i.e. the lambda would still be duplicated if the second copy of the inline function was not removed) so both will call the same std::function constructor.

MuEta
Posts: 15
Joined: Tue Dec 22, 2015 2:44 pm UTC

Re: Coding: Fleeting Thoughts

Postby MuEta » Tue Jan 12, 2016 3:38 pm UTC

I'm just bored at work and was reading the post about the programming language for the XKCD phone. It got me thinking, would it be possible to build an "RNG based" language, where, for example, there is a probability that your variables will shift one bit?

I'm not sure what the purpose of our new random language is, but I think it could be fun to see just how much havoc would be wreaked from a simple bit flip that only happens intermittently. The program could even tell you when the mutation happens, just so it isn't totally evil. I don't know, just some musings.

User avatar
Flumble
Yes Man
Posts: 1943
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Tue Jan 12, 2016 4:16 pm UTC

I don't really see the point in developing a language around it. Just flip some bits in the functions of a library or in the executable or flip them randomly in memory during execution.

schapel
Posts: 244
Joined: Fri Jun 13, 2014 1:33 am UTC

Re: Coding: Fleeting Thoughts

Postby schapel » Tue Jan 12, 2016 4:20 pm UTC

MuEta wrote:I'm just bored at work and was reading the post about the programming language for the XKCD phone. It got me thinking, would it be possible to build an "RNG based" language, where, for example, there is a probability that your variables will shift one bit?.

This is the way most modern computers work. The memory cells are so small that a bit can be flipped by a cosmic ray. So every so often in your programs, a random bit will flip. This is why you want to use error-correcting memory when you're building a large compute cluster for long-running programs -- as the cluster grows larger and as the programs run for longer, the probability of getting a bit flip on a run increases until there's a significant probability that a run will be ruined by one.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Tue Jan 12, 2016 4:43 pm UTC

It isn't that hard to error correct against a relatively known error flux.

It gets tricker when your error correction system has to self-error correct. With a high enough error rate, it becomes intractable.

Might be interesting to know what that rate is.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
chridd
Has a vermicelli title
Posts: 761
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Tue Jan 12, 2016 4:47 pm UTC

MuEta wrote:I'm just bored at work and was reading the post about the programming language for the XKCD phone. It got me thinking, would it be possible to build an "RNG based" language, where, for example, there is a probability that your variables will shift one bit?

I'm not sure what the purpose of our new random language is, but I think it could be fun to see just how much havoc would be wreaked from a simple bit flip that only happens intermittently. The program could even tell you when the mutation happens, just so it isn't totally evil. I don't know, just some musings.
Sounds like the sort of thing an esoteric programming language might do (languages created not for ordinary practical reasons, but for other reasons such as exploring what's possible in programming language design). The Esolang wiki has lists of nondeterministic* and probabilistic esoteric programming languages.

* not the computer science definition of nondeterministic
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · they (for now, at least) · Forum game scores
mittfh wrote:I wish this post was very quotable...
flicky1991 wrote:In both cases the quote is "I'm being quoted too much!"

MuEta
Posts: 15
Joined: Tue Dec 22, 2015 2:44 pm UTC

Re: Coding: Fleeting Thoughts

Postby MuEta » Tue Jan 12, 2016 5:01 pm UTC

I guess this is one of those "if somebody thinks of it, it's already been done before" cases. Drat.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Tue Jan 12, 2016 6:19 pm UTC

I suspect it will be pretty boring to watch as the program will just segfault as soon as one of the higher bits of a pointer is flipped. The chance of the program doing something funny are so much smaller than the chance of it either behaving normally (because the bit is in some sort of struct that is never looked at) or just segfaulting.

If you want to try it anyway you could write a program that (under linux) ptrace()s another program, periodically stops it, inspects /proc/(pid)/maps, flips some bit inside a mapped area and restarts the program. I'm sure other operating system provide similar facilities that enable you to do the same.

User avatar
Xanthir
My HERO!!!
Posts: 5212
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Jan 13, 2016 5:15 am UTC

This wouldn't be a serious language; you couldn't work with pointers or the like. It would be plausible as an esolang with restricted scope, just some arithmetic and looping and the like.

A cute utilization of this might be to allow declaring variables with a specific number of bits, and make the only looping construct a "whilezero $var {...}" that loops until the variable bitflips into a non-zero value - you have some degree of control over the number of repetitions by controlling the width of the variable.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Moo
Oh man! I'm going to be so rebellious! I'm gonna...
Posts: 6329
Joined: Thu Aug 16, 2007 3:15 pm UTC
Location: Beyond the goblin city
Contact:

Re: Coding: Fleeting Thoughts

Postby Moo » Wed Jan 13, 2016 7:24 pm UTC

Anyone have any thoughts on encryption in .NET? Just starting to investigate and I'd appreciate some pointing in the right (or at least interesting) direction. I need to encrypt some JSON before storing to Mongo DB.
Proverbs 9:7-8 wrote:Anyone who rebukes a mocker will get an insult in return. Anyone who corrects the wicked will get hurt. So don't bother correcting mockers; they will only hate you.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Jan 13, 2016 7:48 pm UTC

Real world crypto: encrypt stuff in non-encrypted DB.
Academic crypto: write DB with strong cryptographic guarantees.

First rule of cryptography: don't write a cryptographic algorithm, or write your own use case, because even crypto experts regularly make mistakes in cryptographic code. It won't be secure, because one mistake makes it insecure, and everyone makes mistakes when writing crypto code.

Second rule of cryptography: You are really just obscuring stuff due to the first rule. So just use Rot13. Or Rot12 for extra obscurity.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Moo
Oh man! I'm going to be so rebellious! I'm gonna...
Posts: 6329
Joined: Thu Aug 16, 2007 3:15 pm UTC
Location: Beyond the goblin city
Contact:

Re: Coding: Fleeting Thoughts

Postby Moo » Wed Jan 13, 2016 9:09 pm UTC

Oh good grief... the more I read, the more I realise I have no idea what I'm doing. And I have to write this up in a technical spec tomorrow so I don't have a lot of chance to play around... what algorithm to use? To even use one, or (as Yakk suggests) leave it to people who know better? But then which library to use? To salt or not to salt? Where to store the key? And the IV(s). Do I need to generate a new IV for each user whose information I need to store? Where do I store them all?

Also, as Yakk seems to have guessed, I have control over the data before it leaves my app. I have no control over the security of the DB. So I have to do what I can with the data while I have it.

This is a mini rant rather than actual questions. The data is luckily not thAAAAAt sensitive, it's mostly to satisfy our Governance people... Still. Poop.
Proverbs 9:7-8 wrote:Anyone who rebukes a mocker will get an insult in return. Anyone who corrects the wicked will get hurt. So don't bother correcting mockers; they will only hate you.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5086
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Jan 13, 2016 9:48 pm UTC

At work we store the encryption key inside the same database as the encrypted columns (though in a separate table)...

I'm not sure that this isn't a dubious practice, but it's easy to manage anyway... downsides of course to storing in a non-centralized location is you have to deploy it to each place individually.

User avatar
Flumble
Yes Man
Posts: 1943
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Wed Jan 13, 2016 10:15 pm UTC

Do you want to encrypt the information using a key that's private to the user or one that's private to your interface?

Assuming your interface is secure, you can use a single key/IV/salt/whatever to encrypt and decrypt the information and seperate it completely from access control and user management. The weakest link is then min{correctness of your code, security of the container your interface is running in, entropy in the IV, security of the chosen crypto algorithm}. In most cases, it turns out either your code is flawed or the software it's running on is flawed. So adding more entropy to individual encrypted fields (entropy which you have to store in the same database basically unencrypted) doesn't help you.

Personally, I'm in favour of having the user do the encryption and decryption (using their private keys). But passwords get lost for whatever reasons and you want to be able to recover the data despite not having the user's private key.

For .NET RijndaelManaged seems to do the trick regarding cryptography. You can just ask it for an IV and key (and then store those in your project or in the code) and all its defaults are NSA-tier secure.

Note that I'm not talking about handling user credentials in any of this. That stuff includes hashing passwords and such. And that should probably handed off to a completely different piece of software.
And I'm also not talking about handling the connection security. Wait, I am now: The communication between your interface and the database must at least guarantee integrity (and hopefully all the other aspects too, so an eavesdropper can't profile user behaviour), whereas the communication between your interface and the user must guarantee all security aspects (since the data is no longer encrypted at this stage).

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jan 18, 2016 3:02 pm UTC

We have a large java application split over a number of git repositories.
Sometimes I want to quickly see if a series of pulls would be disruptive, and I do something like:

Code: Select all

>>> git log --oneline HEAD..origin/master

And I get

Code: Select all

20aae2 Fixed ticket ABC-101
72aae2 Build stuff filled with 1.27abc like numbers that mean nothing to anybody
a32dee Stupidly long commit message filled with domain/company/project/thing/god-damn-java-paths/who-invented-this-shit and no regard for command line users and nobody reads these things anyway
87ebb2 Just some subtle changes that shouldn't really affect much


And I look at that and sigh, and with hesitation type

Code: Select all

>>> git show 87ebb2

And my screen is covered in text, a blizzard of +'s and -'s and oh my god I've never seen so much red and green together.

But fine, I can deal with it, I'm sure it's fine.
And I can always go back if the pain caused by this pull is too much.

Code: Select all

>>> git pull
...
Updating abcdef to fedcba
...

Wait, that's not 20aae2...

Code: Select all

>>> git log abcdef..fedcba
commit fedcba...
Author: Person <person@company.ac.uk>
Date:   Like, 5 seconds ago.

    Added method to class

Fuck you.


TLDR: Basically, I don't like pulling around here, and please write sensible commit messages
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 18, 2016 10:16 pm UTC

So the lesson is you should fetch and merge instead of pull? I don't see a real git problem here. You could also use the reflog to go back if things go wrong.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Jan 18, 2016 10:29 pm UTC

My problem wasn't with git. :wink:
Image

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Coding: Fleeting Thoughts

Postby Wildcard » Mon Jan 18, 2016 10:47 pm UTC

Xenomortis wrote:

Code: Select all

>>> git log abcdef..fedcba
commit fedcba...
Author: Person <person@company.ac.uk>
Date:   Like, 5 seconds ago.

    Added method to class

Fuck you.

I see your point about the useless commit message, but...you really shouldn't be using `git pull`. (At all, ever.) You should just do `git fetch` followed by a `git merge` (or `git merge --ff-only` or `git merge --no-ff`). Then you won't have this problem.
There's no such thing as a funny sig.

User avatar
Xanthir
My HERO!!!
Posts: 5212
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Tue Jan 19, 2016 7:44 am UTC

Fuck y'all, I'm getting "git pull --rebase" tattooed on my knuckles.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


User avatar
PM 2Ring
Posts: 3619
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Mid north coast, NSW, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Fri Jan 22, 2016 11:15 am UTC

From SO Python Chat:
F4z wrote:hello, I keep getting confused with TypeError and ValueError, can someone kindly simplify for me what those two are?

bereal wrote:Ok, you go to bed and see another girl instead of your gf - that's ValueError. You see a raccoon - that's TypeError.

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Fri Jan 22, 2016 3:30 pm UTC

PM 2Ring wrote:From SO Python Chat:
F4z wrote:hello, I keep getting confused with TypeError and ValueError, can someone kindly simplify for me what those two are?

bereal wrote:Ok, you go to bed and see another girl instead of your gf - that's ValueError. You see a raccoon - that's TypeError.

Hey, let's not be hasty! If you hail from C, all it takes is a quick cast!
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
Sizik
Posts: 1155
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Coding: Fleeting Thoughts

Postby Sizik » Fri Jan 22, 2016 3:39 pm UTC

commodorejohn wrote:Hey, let's not be hasty! If you hail from C, all it takes is a quick cast!


I'm pretty sure bestiality is undefined behavior.
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri Jan 22, 2016 4:25 pm UTC

Code: Select all

$ cat bug.cpp                               
bool f(bool b)
{
    return b < 0;
}
$ g++-4.9 -c -Wall -Wextra bug.cpp
$

Thank you, GCC, for warning about that pretty-nonsensical, always-constant comparison. :roll: (And thank you to the C++ committee for allowing < and > on bool, though maybe I could by that was the least-terrible solution.)

(And this isn't even the first problem I hit today that I think GCC could and should have warned about but didn't...)

(Edit: to be nicer to GCC, GCC 6 (in development) warns about it. 5.2 doesn't though.)

User avatar
Flumble
Yes Man
Posts: 1943
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Jan 22, 2016 10:38 pm UTC

EvanED wrote:(And thank you to the C++ committee for allowing < and > on bool, though maybe I could by that was the least-terrible solution.)

It's probably a side-effect rather than a solution: booleans may be implicitly promoted (note: not even converted in the case of an integer) to other types.

What's the warning message from GCC 6 anyway?

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Sat Jan 23, 2016 2:33 am UTC

Flumble wrote:
EvanED wrote:(And thank you to the C++ committee for allowing < and > on bool, though maybe I could by that was the least-terrible solution.)

It's probably a side-effect rather than a solution: booleans may be implicitly promoted (note: not even converted in the case of an integer) to other types.
Right, but that was a choice by the language designers. One that was bound at least a little by backwards compatibility and thus may have been the least of all evils, but a choice nevertheless.

What's the warning message from GCC 6 anyway?
It's an instance of -Wtautological-compare; it's some variation of "comparison is always false." I don't have access to the exact message ATM.

User avatar
Flumble
Yes Man
Posts: 1943
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Sat Jan 23, 2016 2:47 pm UTC

EvanED wrote:
What's the warning message from GCC 6 anyway?
It's an instance of -Wtautological-compare; it's some variation of "comparison is always false." I don't have access to the exact message ATM.

Ah, that's better than a warning that it's casting/promoting a bool to an int.
Though, now that I've looked into GCC flags a bit: why didn't -Wbool-compare recognise this comparison in the first place? That's silly.
And it's also silly that nor -Wall nor -Wall and -Wextra enable all warnings.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Sat Jan 23, 2016 3:19 pm UTC

-Wall-i-really-mean-it
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5086
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Jan 25, 2016 3:23 pm UTC

Little endian annoys me.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Mon Jan 25, 2016 4:54 pm UTC

EvanED wrote:
What's the warning message from GCC 6 anyway?
It's an instance of -Wtautological-compare; it's some variation of "comparison is always false." I don't have access to the exact message ATM.

Just for the record, I was slightly wrong; it's -Wbool-compare rather than -Wtautological-compare:

Code: Select all

$ g++ -Wall -Wextra -c bug.cpp
bug.cpp: In function bool f(bool):
bug.cpp:3:14: warning: comparison of constant 0 with boolean expression is always false [-Wbool-compare]
     return b < 0;
            ~~^~~
$ g++ --version
g++ (GCC) 6.0.0 20160114 (experimental)

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 25, 2016 5:21 pm UTC

Xeio wrote:Little endian annoys me.

Conjecture: The only people that bash little endian are those who have never written assembly code or device drivers for a big endian system. But I think there is already a religious war thread on this topic :D.

What is REALLY annoying is crazy bit numbering. In the RFCs describing IP and related protocols bit 0 is the most significant bit. I.e. bit 0 equals 0x8000. Except for 32-bit fields where it is 0x8000'0000. Or 48-bit fields where it is 0x1'0000'0000'0000. Yeah, that totally makes sense.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5086
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Jan 25, 2016 5:49 pm UTC

Well, I'm only really annoyed I can't select 4 bytes, convert it to an int, and get a sane number output.

I have to take the last byte, then the 2nd to last...

There's probably a binary viewer that does that in some fashion, somewhere, but the first one I found didn't and [/whine].

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Mon Jan 25, 2016 6:12 pm UTC

Well I would argue that the problem here is that our natural way of writing numbers does not make sense from a mathematical/algorithmic point of view. For little endian byte i stores bits [8 * i, 8 * i + 7] where for big endian we need to know the length of the number to determine the significance of a bit.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5086
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Jan 25, 2016 7:06 pm UTC

That's a secondary issue I have at the moment (length of the number), I'm trying to reverse engineer a binary file format. Endianess is just a little whiney annoyance on top of the difficult work of revers engineering. :wink:

User avatar
hotaru
Posts: 1021
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Coding: Fleeting Thoughts

Postby hotaru » Mon Jan 25, 2016 10:35 pm UTC

Xeio wrote:Well, I'm only really annoyed I can't select 4 bytes, convert it to an int, and get a sane number output.

what language are you trying to do it in? you can't just do this?

Code: Select all

uint32_t four_bytes_to_uint32(uint8_t bytes[4])
{ return (bytes[0] << 24) +
         (bytes[1] << 16) +
         (bytes[2] <<  8) +
          bytes[3]; }


korona wrote:Well I would argue that the problem here is that our natural way of writing numbers does not make sense from a mathematical/algorithmic point of view.

it actually does make sense when text is written from right to left (as in arabic). the problem is that those silly europeans decided to write everything backwards, and then forgot to flip their numbers around to match.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 7 guests