mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Nice article!

I think we are really starting to see a turning point these days. A lot of free software is now catching up to commercial software, or at least, close enough that it becomes hard to justify the cost of buying it.

In my opinion, for amateurish work on almost anything, there is an adequate FOSS solution out there. Just like LibreOffice vs MS Office, unless the office suite is your bread and butter, LibreOffice is probably going to be perfectly adequate (light work, occasional use, etc.).

But what's been happening now is that a lot of FOSS software is catching up, even in professional / engineering fields. Like many game development efforts that rely on Blender instead of some other (expensive) "professional" 3D modeling software. Like the plethora of electronics design software (EDA/eCAD) that mostly rivals commercial solutions. Like GIMP that rivals Photoshop. Like FreeCAD that is starting to look a lot like SolidWorks. Like Code-Aster / Code-Saturn / Salome that hands-down beats most of the very expensive FEA / CFD software packages.

I'm just wondering... what does that entail for these commercial software companies and their employees?

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Did you try the mingw32 package?

You can install it with:

$ sudo apt-get install mingw32 mingw32-binutils mingw32-runtime

or whatever the equivalent packages are for Kali Linux (you might have to manually download the .deb files for these, and install them with $ sudo dpkg --install name_of_package.deb).

This will make it easier because MinGW comes with the standard Windows headers and libraries, and you won't have to fiddle around too much with the include-paths and all that. See compilation instructions here.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I also played with dolls momentarily as an infant (4-7 or so). I never really played with GI Joes, although I did like to play with TMNTs. But I mostly played with legos and playmobil (which is very gender-neutral). I think to each his own, and parents need to be flexible.

I have mixed feelings about the whole gender-neutrality thing (as Agilemind describes it). Whether gender preferences (e.g., girls like dolls, boys like trucks / action figures) are innate or acquired (most likely a mix of both) is not all that relevant to me. Part of growing up is learning to socialize, and part of socializing is having common interests (i.e., "fitting in"). And in that sense, wanting your child to develop interests ascribed to their particular gender is part of wanting that child to fit in well with other children of the same gender and make friends and all that. As one parent (pair), you can't change the fact that other kids will have gender-biased upbringings and therefore, there is a similar expectation on your child's upbringing, so that he/she fits in with other kids. As such, I don't necessarily see it as a conservative-values issue of wanting to impose traditional gender roles.

But then again, there needs to be room for individuality, and flexibility on the part of the parents. If the child seems to like some things that are somewhat non-traditional for his/her gender, then let it be so, and foster whatever interests seem to make your …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As AD said.

And,

This book is of mine?

That's definitely not correct, but you might say "This book is one of mine." (i.e., "mine" takes the place of "my books"). The "of mine" can also be used instead of "my", as in: "This book of mine is ...", instead of "My book is ...", but this is mostly archaic or lyrical (e.g., "Sweet child of mine").

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I think that obviously giving a toddler a smartphone is at your own risk (of getting it broken). I'm not sure they are particularly harmful though. My toddler niece sometimes (rarely) plays with her mommy's smartphone. She would randomly navigate the menus (can't read) until she hits a picture of someone in the family and becomes overjoyed, and quickly navigates randomly to some other menu. I don't see it as particularly educational or anything, but most games toddlers play are kind of like that anyways (doing random stuff and being randomly amused by it). But again, there is a high risk-level for the smartphone (breaking it, messing up the settings, etc..). I think it can't really hurt too much for the toddler to handle a smartphone (never too young to get acquainted with tech.), but it shouldn't be a big part, and it never is, cause it's kind of a boring toy for a toddler.

That's my 2 cents.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Using ofstream file("C:\\sample.txt"); should work, unless you do not have to permissions to create a file in the C:\\ directory.

In general, in C++, if you want more control over the file-system (folders, files, etc.), you need to resort to a library for that (at least, until it becomes standard, probably in C++14, I think). You can use the Boost.FileSystem library, or any other file-system manipulation library (e.g., in Qt).

Otherwise, you will have to use API functions directly, such as Win32 API functions (Windows).

But again, your program will only have the file permissions of the user account it runs under. If you need to read / write files in admin-only folders, you will have to run the program with administrator rights.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You have a buffer overflow on your buf array. The array can store 4 values, and you address it with buf[isBuf] where isBuf can be 4. This will write to memory one character passed the end of the buf array. When you have the zeroAddr present on the function's stack frame, it is probably sitting right after the buf array, meaning that writing beyond the end of buf is harmless because it just writes on the memory occupied by zeroAddr. But when the variable is not there, you write passed buf which either writes in invalid memory (beyond function's stack frame) or it overwrites the value of isBuf to a much higher value (a character) which then leads to a crash (accessing invalid memory).

I think that you should just change your condition on isBuf to:

    if (isBuf==3)
    {
      ..
    }

instead of 4. That should fix it.

Whenever you have this kind of behavior (adding a variable fixes the problem), it almost certainly means that you have memory corruption, i.e., reading or writing passed the end of an array or something like that.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Hello and Welcome!... btw, you have one heck of a name to be stepping into the world of IT!

dennis.ritchie commented: thank you +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The strcmp function returns 0 when the strings are the same, i.e., you should do:

if( ( strcmp( ch, "*" ) == 0 ) || 
    ( strcmp( ch, "/" ) == 0 ) || 
    ( strcmp( ch, "%" ) == 0 ) || 
    ( strcmp( ch, "+" ) == 0 ) || 
    ( strcmp( ch, "-" ) == 0 ) )

The reason for this is that strcmp can also be used to alphabetically sort strings (it returns a negative number if alphabetically "less-than", and vice versa).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Woot Woot! They solved the problem in the latest chrome update (version 33.0.1750.152).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yes, my GC was deterministic. It also dealt with circular references.

Yup. That's exactly what I suspected. ;) I would have been very surprised to find out that you used a non-deterministic GC in high-reliability software like that. And given that the only reason to have a centralized reference-counting scheme is to handle cycles, it was a very good guess that this kind of "GC" was what you referred to.

To me, a garbage collector needs to involve "garbage" and "collection". The former being objects that are not yet deleted, but no longer used, i.e., discarded items. The latter being some sort of background process that, once in a while, goes through all those discarded objects and deletes them. A deterministic reference-counted scheme does not follow that definition, in my book, because it lacks both. As soon as an item is discarded, it is deleted, meaning that it never lingers as "garbage". And if there is no garbage, there is nothing to "collect". Even wikipedia (as the voice of the majority, sort of) is a bit ambiguous on whether pure reference-counting could really be considered as garbage collection. It loosely seems to consider that the terms garbage collector really only refers to uses of algorithms like semi-space collector, mark-and-sweep, or mark-and-don't-sweep, which are techniques that would definitely fit my definition of garbage collection.

By the way, the latest C++ standard also allows for conservative garbage collection. How it makes it possible has to do …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Smart pointers are fine, but unless they are combined with reference-counting life-cycle management, are of limited use. I'm not that familiar with C++11's shared pointers, so it looks like I have some additional research to do. :-)

Yeah, you probably should. ;) Shared-pointers (shared_ptr / weak_ptr) are surprisingly robust and dependable. They are indeed reference-counted pointers. Moreover, the reference-counting is thread-safe (via atomic operations). As far as I'm concerned, it renders any other kind of reference-counting scheme deprecated, i.e., there's just no need, if you were to write a completely new library or application, to create another reference-counting scheme. And when you account for all the situations when unique ownership is appropriate (e.g., RAII-style data members or base-class, or unique_ptr pointers), and all the situations when shared ownership is needed (which are rare, actually), there is very little left (or none?) that would justify a full-blown garbage collector (i.e., 99.9% of the time, using a garbage collector is like killing a fly with a sledgehammer).

Also, the proof is in the pudding. Most of the fairly serious libraries that I have ever looked at generally use either an intrusive reference-counting scheme (for older libraries, mostly), or they rely on shared_ptr (or a similar variant, such as QSharedPointer in Qt, or IntrusiveRefCntPtr in LLVM), or, they don't really use shared ownership at all (and often, you don't have to, because software often naturally writes itself without it). Garbage collector libraries for C++ have been available for decades, but I …

rubberman commented: Thanks Mike. I haven't studied the C++11 standard to any extent. Time for some homework! :-) +12
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

In any case, throw() specifies that it may throw ANY exception.

That's wrong. Maybe you forgot the negative in that statement, it should say: "throw() specifies that it may NOT throw ANY exception."

Here is the whole story. Exceptions are standardized in the C++ ISO Standard document. Their behavior is fully specified and compilers mostly comply to that specification, and have done so for a couple of decades now (at the very least, since 2000 or so). The behavior of exceptions is specified in terms of how the stack should be unwound following the throwing of an exception, what should happen in special cases (e.g., calls std::terminate() if an exception is thrown during the stack unwinding (e.g., from a destructor)), and how the appropriate "catch" statement is selected. That's all the "observable" behavior that is specified.

Note, however, that the standard says nothing about the implementation of those behaviors, i.e., compiler-vendors are free to implement those mechanisms any way they see fit, as long as it behaves correctly. However, most compilers comply with the Intel Itanium C++ ABI standard which has a detailed and standardized description of the so-called "zero cost exception handling" implementation, see here. In fact, the only modern compiler that does not implement and comply to the Itanium ABI standard is the Microsoft compiler (MSVC), which is, of course, the last compiler you would use if you care about standardization or reliability at all (i.e., MSVC is not really a production-quality compiler).

So, …

rubberman commented: I stand/sit corrected! Thanks Mike. +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

C++ is based on C, and C is nearly a subset of C++ (nearly, because there are some incompatibilities, but mostly, these differences are technicalities). C++ has a lot more features than C:

  • Function and operator overloading (i.e., same name, different parameters).
  • "Object-oriented features", i.e., classes with different access right (private, public, protected), member functions, static members, inheritance, virtual functions (i.e., polymorphism), etc...
  • Namespaces, i.e., the ability to categorize code to avoid name-clashes between things with the same name in different libraries.
  • Const-correctness, i.e., the ability to make a promise not to modify a variable and propagating that promise.
  • Resource Acquisition Is Initialization (RAII) which uses non-trivial constructors and destructors to handle the allocation and deallocation of resources in a way that is automatically triggered leaving scopes (functions, objects, etc..).
  • Exceptions which are used to signal exceptional conditions (e.g., errors) in a channel that is parallel and "safe" compared to C-style error-code mechanisms.
  • Templates which allow for compile-time parametrization of code and data-types according to other types or compile-time constants. This allows for "Generic Programming" (GP) and "Template Meta-programming" (TMP), which are two central programming styles in C++.

The rest of the differences are most technical. And also, of course, the C++ standard library is a lot bigger (and well designed) than the C standard library (which is also included as a subset of the C++ standard library).

That just about sums it up.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Line 73 should be:

return g_spLog;

not

return sp;

because sp is null, and when you return it, and immediately assign it to g_spLog at line 55, you end up with a null pointer in g_spLog.

BTW, despite your efforts, you are still subject to the "static initialization order fiasco" with your code. If you end up calling CSingleton::Create() during some static initialization somewhere, you might enter the Create() function when the g_spSingleton pointer is not yet initialized (and thus, not null, but not valid either). You should use local static variables to solve that problem.

Also, you don't need to initialize shared-pointers to "null", because their default constructor already does that, so, your static variable definitions could just be:

BOOSTSP<CSingleton> g_spSingleton;
BOOSTSP<CMyLog> g_spLog;

and that would be sufficient.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't know that you can find out what the password for root is, unless you have it already and can thus login as root. There would be no point in having a password if you can find out what it is without having the proper credentials.

However, one common issue (with beginners) is that they try to issue a su command (which temporarily switches to root user (super-user) within the current terminal) and it doesn't work because they don't know the root password. Normally, if you have super-user privileges on your account, you can use the sudo command to run a particular command under super-user (e.g., $ sudo yum install ..). You can also use that command to do the su command, i.e., you can do $ sudo su, which will require your user password (not the root password), and will grant you super-user status (root). After that, if you want to change the root password (which is randomly generated upon installation), you can use the passwd command.

You can also recover from having forgotten the root password by booting into single-user mode. See instructions here.

But if your user account is not a "sudoer" (meaning you can do sudo from your user account) or you don't have physical access to the computer, then it means that you do not have the necessary credentials to be a super-user on the system. And at that point, trying to get the root password would be tentamount to hacking the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There are alternatives to google if you want more unbiased results, in particular, you can use DuckDuckGo. Here is a comparison of results for "php programming", DDG vs Google. As you can see, you far less ads or general "preferred" websites, and instead, more diverse and relevant results.

Google is largely turning into a man-in-the-middle for the internet as a whole, and that's a huge problem. On the one side, you have all the people depending on google to allow them to find stuff on the internet, and on the other side, you have tons of businesses that rely almost exclusively on being easy to find from google in order to be able to get customers. That is a huge position of strength for google, meaning that they can make or break any business, and thus, they can extort everyone. They used to just sell ads on their sites. Now, they can extort businesses for their right to be visible on the internet. And that's why their search results are so biased now.

As far as filtering is concerned, I don't of any good tool that exists for that. It is quite difficult to "filter" searches without actually creating your own search engine, because it's really not that easy to discriminate between different categories of content (ads, commercial, educational, etc.) without doing a lot of indexing of your own. I would suggest you look into the alternatives to google, many of which actually index …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

A platform to tell the world that you just went to the toilet, and if yo're lucky you can post a photo of this amazing event.

That gives me an idea of a pretty useful app. How about an app that can analyse a picture of your stool and tell you if you are healthy, if you ate too much or too little of something (e.g., fiber, spices, etc.), if you drink enough water, or if you should go to the doctors right away, because experts can know a lot of stuff like that just by looking at the stool. That would really be the apogee of the "app madness", taking pictures of your own shit!

Reverend Jim commented: Great idea. An AI app you can call Brains For Sh!t. +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Whats new in the software development world, last I heard wechat and instargram where the next big things

Things like wechat and instagram have very little to do with software development. Saying that wechat and instagram are the next big thing in software development is like saying that tablets are the next big thing in the molding of plastics. Molding plastic for one thing is as easy as for another, and new products are rarely revolutionary in the techniques used.

It would be more accurate to say that these things are the next big thing in social media, or internet marketing, or in the mobile markets. But from a technical "software development" point of view, these things are trivial and are not pushing any boundaries, as far as I'm aware. So, be sure to focus on the correct terms. If you want to know what's the next "app bubble", then that's one thing, but software development is something else.

From looking at current job postings and stuff, clearly, the current big thing in software development is data mining and predictive analytics. Also, computer vision is booming (e.g., kinect on steroids, facial recognition, vision-guided self-driving cars or robots, etc.). And, of course, more distributed software paradigms (e.g. cloud stuff, more inter-connected smart devices (in home, car, etc.), etc.). I think these are the current and next big challenges in software development.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

When you do cin >> currentPath; it will only input the next word, i.e., it stops at the first space character. If you want to input a complete line, you have to do this:

getline(cin, currentPath);

that will read the entire line, including space, up to the new-line character (where the user hits enter).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It is generally not safe to change the value of a constant. The const_cast operator allows you to suspend the protection against doing this when you know it is safe to do so. In some cases, const_cast can be safely used, but not in this case.

The danger with changing the value of a constant is that const tells the compiler that the memory will never be written to, which means that the compiler is allowed to do some optimizations like putting the variable in read-only memory sections, or optimizing away the variable altogether.

The only times that it is safe to use a const_cast is when you know for sure that the variable has not been optimized away or put in read-only memory... and to know that, it takes a bit of insight into the language and compiler mechanics, which is too long to explain here.

So, if you recklessly do a const-cast and write to read-only memory, you will get a crash / error, which is probably what happened to you.

If you want to be able to change the value of path, then don't make path into a const. And you should probably use std::string instead too. As in: std::string path = "C:\\";.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, as you probably know, the author (Andrew Koenig) of that book used to be quite active here on Daniweb, see his profile. I would suggest you ask him directly. And as far as buy vs steal, you could just get the unofficial ebook, and wire (e.g., PayPal) some money to Mr. Koenig or his wife.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I beg to differ, CentOS is a very well-established distro of Linux. It is one of the main free alternatives to the big names in server distributions of Linux (RHEL and SLES). If you want a stable server-grade Linux distribution for free (no support plan costs), then CentOS is really good option, so are the up-stream distributions like Fedora (ahead of RHEL) and OpenSUSE (ahead of SLES).

I need to use apt-get and ipkg in my CentOS.

I don't understand why you want to install a Debian package system on a Red Hat system. What's wrong with the Red Hat package system (rpm and yum)? The apt-get command is equivalent to yum, but the latter is for distros that use Debian packages (Debian, Ubuntu, Mint, etc..), while the former is for distros that use Red Hat packages (Fedora, RHEL, CentOS, SLES, OpenSUSE, etc..). Similarly with ipkg / dpkg versus rpm.

Is there a really good reason why you want to rip out the Red Hat package manager from your OS, and transplant the Debian package manager instead? I don't think this is really possible without some crazy amount of work.

And what are you going to do once you have installed Debian package managers, which repository will you connect to? Debian repos? Are you gonna translate your own packages (take rpm packages, convert them to deb packages, upload them to a private repository, and the install them with apt-get)? Seems like a lot of trouble.

If …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Using a BigInt library is one solution.

Also, what are those digits?

If this is just a very big number, then you might just use a floating-point type instead (float or double) which don't really have an upper-limit (well, they do, but it's like 1e308), and instead, have a limited-precision (about 18 significant digits).

If the digits are actually something like a serial number, social security number, bank account number or anything like that, then you most likely don't need to be doing any math operations on those numbers (e.g., you can't add two social security numbers!). So, in this case, you don't really need to store the number as an actual number (integer), but instead, you could just store it as a string (text), or some other ad hoc representation (like 5 integers, one for each chunk of 5 digits). That's what you normally do for long numbers that are not mathematical in nature. This is because the BigInt classes are usually overkill for this situation because of all the math operations they bring into the picture (that you won't use).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

is it possible for me to write my own class deriving from iostream that would deal with cin and cout, but act as one stream.

Yes and no. To do this, you would have to violate the interface of iostream. The problem here is that cin and cout are not really connected with each other (except for synchronization), they are two distinct streams. Whatever you write onto cout, you will never be able to read out of cin. They are two distinct streams, i.e., like two distinct files. This means that if you were to create an iostream that takes all inputs from cin and puts all output to cout, you would not get the same behavior as you get from a iostream like fstream or stringstream, which both operate on a single buffer. For example, if you have a stringstream, you can write stuff to it, and then read it back out afterwards, and the same goes for fstream. The point is, this behavior is the expected behavior you get when using an iostream, and you will never be able to get that behavior out of standard streams (stdin, stdout) because they are separate streams.

You could do some trickery to merge the two standard streams, which is possible through OS-specific functions. For example, you could pipe stdout into stdin, and then, you would get the correct iostream behavior. However, with that, you lose the actual console input completely (and probably the console output too), and at …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, it's true that this may not be appropriate for whatever is Labdabeta's actual problem in its broader context. And, like you, I would invite him to give us more information on that.

However, this is far from being an unusual solution. The code I posted above, or a variation thereof, is extremely common. I have written such code in many places, and I have seen it in many other places too. And there is nothing unusual about the situation Labdabeta is in.

I would say that the only thing that is unusual here is that Labdabeta seems to require a bi-directional (I/O) stream. That is very rarely needed. A true bi-directional stream, meaning that you can go back and forth between reading and writing on the same data, is rarely needed, and never a good idea either (typically, do most operations in memory, and then, dump to a stream, or vice versa, take all from the stream and then operate in memory).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

However cout uses ostream instead of istream and therefore its common ancestor with fstreams would be ios.

Well, naturally, cout uses ostream because cout is an output stream, not an input stream. If you want an input stream, you have to use cin. And fstream derives from both istream and ostream, btw.

Generally, if you want to have a stream object that is either a file stream or a standard (console) stream, or a string stream, for that matter, the general solution is to have a pointer to a ostream or istream, depending on the direction you need.

You cannot, however, have a generic bi-directional stream (iostream) because only some stream can allow that (e.g., files and strings), but not standard streams (cin / cout). And this is the case whether you use C++ streams or C-style IO functions, because the standard streams behave the same in both cases. The only difference is that in C++ you are forbidden at compile-time from attempting to do input operations on cout, or vice versa. With the C functions, doing so is permitted by the compiler, but will result in an error at run-time.

So, if you need iostream, then you can use that too, but only for things that actually support this bi-directionality, which excludes the standard streams (and any other similar streams, like internet socket streams).

Here is how you would typically handle having a generic stream:

class any_ostream {
  private:
    std::ostream* out_str;
    bool should_delete;

    // non-copyable:
    any_ostream(const …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Clang is great. Not perfect, not problem-free, not super-clean, not without its challenges, but still great.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Have you had much experience with it?

Don't pay attention to what I said, I was just venting some repressed anger. I've just started to dig into clang's code, and yesterday, I spent several hours chasing down a resource-leak issue through the maze that is the front-end architecture of clang, just to find that they intentionally leak most of their high-level data structures, and even more aggregious, they hide the leaks so that memory profilers will give them a "clean bill of health". Basically, they constructed such a messy architecture that they don't know how to deconstruct it cleanly, and so instead, they just leak it all, including file handles and the whole shabang. Very nasty stuff. As soon as you depart from RAII in C++, you set yourself up for failure in the long-run, IMHO.

There are also tons of nasty hacks that I had never even dreamed of in my worst nightmares, and with no obvious reason for using them. And I have barely seen a small cross-section of the code so far.

I'm sure that other compilers are even more messy under-the-hood. Clang is indeed nicer and faster, and more easily adaptable due to being coded in C++. However, that doesn't guarantee that things won't get messy, and they already have. And, it is still very much a work in progress (the code is riddled with "FIXME" and "TODO" stuff everywhere).

But again, I'm just venting here.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't want to make this into yet another gun debate.... I'm tired of this BS. Your quoted stats are irrelevant here. And a survey about what people buy guns for does not correlate to what people use them for. What I was referring to is this study which establishes that nearly 50% of the time a gun is used for something other than hunting or target-shooting, it is use to commit suicide, more so than homicides (voluntary or accidental), and far more so than self-defense. It doesn't matter what stupid reason they once bought it for, it only matters what they ended up using it for (which, statistically, is either on themselves or on their family, or both). Here are few other random stats on that:

The largest category of firearms fatality is suicide, not homicide. In 1997, 54 percent of all gun deaths were suicides, and 42 percent were other homicides (justifiable, accidental, or criminal). (CDC / NCHS, 1997 deaths reports)

About six out of 10 suicides are committed with firearms. (CDC / NCHS, 2010)

People living in a household with a gun are almost five times more likely to die by suicide than people living in a gun-free home. (Kellerman et al. 1992, link)

But this is completely off-topic, because the OP requested "little known facts", and I don't consider the things I listed here as "little known", on the contrary, you have to be living in fantasy-land to be unaware …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Regarding the speed cost, it may add up because if you travel a full directory tree (with > 1M files entry) that is memory buffered, going from one item to another is just a jump of ptr but copying the structure probably becomes a time-critical event.

Uhmm.. I'm not sure what you mean here. The cost of that extra copy of the object is not going to become more expensive as the record becomes bigger. It might add up, but it doesn't become worse. And, it will always remain an insignificant fraction of the whole execution time.. because everything else adds up too.

(yes I know, it is more probably the memory access lag)

Well, that depends. The memory access lag (i.e., reading off the file list from the file-system on the hard-drive) might not necessarily be that bad because of caching (temporarily putting HDD memory on RAM for quick access), pre-fetching (anticipating up-coming reads), and other things that can streamline that access. Of course, reading off a list of files on the HDD is always going to be very slow in terms of memory access. But, even if that wasn't there as a bottle-neck, you would still have the context-switch overhead. The thing here is that reading off the file-system requires a temporary context-switch from user-space (where applications run) to kernel-space (where the OS runs), and that is expensive enough by itself to render the copying cost insignificant.

Consider this:
- Cost of copying …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Over the past 50 years, gun owners have been responsible for over $2 billion in wildlife conservation in the United States due to 10% tax on guns and ammo.

That's great! But the target is wrong. Statistically, one of the primary uses for firearms is to commit suicide. So, the tax on firearms should go towards funding suicide prevention programs and mental health treatments.

Fun fact:
The largest living organism in the world is a mushroom in Oregon. link

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Oh yeah, primary elections are so dirty, in every party. One thing is always guaranteed, the guy that is backed by the establishment and the fundraisers is going to win the primary.. the vote itself is virtually meaningless. Primary races are all about convincing the establishment of the party of that you have a better chance than the other guy to win the actual election. Once the establishment and the fundraisers have made their choice, there is nothing they won't do to guarantee a win for their favorite candidate in the primary election. Remember all the dirty tricks Karl Rove pulled on just about anyone standing in his way in primaries. It's the first time I hear of actual election fraud (as in, stuffing fake ballots in the boxes) in a primary election, but it does not surprise me at all.

In fact, primary elections are really where the real battles are fought. For a real principled politician to be able to get through a primary election and come out victorious, it takes a real miracle, because they always get crushed under the weight of the establishment lap-dog candidate's ability to raise funds and to pull dirty tricks. That's why there are so few non-lap-dog politicians elected, ever. By the time you get to the actual election, you have a choice between two corporate lap-dogs, and all you get to pick is the color on their banner.

And I agree with diafol, from a perspective of outside from the US, …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Ok, so let me get this straight. Currently, your code ends up doing to following thing for each iteration:

  1. Fill in the data into a WIN32_FIND_DATA object (within your input iterator) via the FindNextFile function.
  2. Copy-construct a new WIN32_FIND_DATA object as part of "push_back()".

And you want to change it to be:

  1. Fill in the data into a new WIN32_FIND_DATA object (within the vector) via the FindNextFile function.

The problem with doing this is that there is really no way to avoid constructing the WIN32_FIND_DATA object before you can fill it with data from the FindNextFile function. That's by design of the FindNextFile function. The best you could do would be to default-construct a new WIN32_FIND_DATA object in the vector (and because it is a C struct, default-construct is trivial, meaning that it does nothing at all), and then fill it in. In other words, the most efficient version would be this (as a simple loop):

std::vector<WIN32_FIND_DATA> vwfd;
HANDLE handle;
while( /* still have files.. */ ) {
  vwfd.emplace_back();
  FindNextFile(handle, &vwfd.back());
}

As far as finding a way to coerce that into a back-inserter / input-iterator framework, I don't think it's worth the trouble. It could be possible, by using some kind of proxy class.... but really, you might just try to rely on NRVO (Named Return-Value Optimization), with something like this:

struct find_file_iterator {
    HANDLE handle;

    WIN32_FIND_DATA operator*() const { 
      WIN32_FIND_DATA wfd;
      FindNextFile(handle, &wfd);
      return wfd;
    }
    find_file_iterator& operator++() { return *this; }
    ... …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I presume your "Black Panther" reference was implying that Democrats have done the same.

I believe that jwenting was referring to an over-hyped occurrence where, at a polling station in a predominantly black neighborhood, one of the security person there (like they always have at voting stations) was dressed in a way that was reminiscent of the Black Panthers movement (all black, leather jacket, etc.). However, the guy just happened to be black and be dressed this way, and was in no way affiliated with the organization in question. But someone filmed him, just standing near the entrance as any security personnel naturally would, and those images went viral in the right-wing media circus. I believe there was also a similar benign occurrence many years ago. And that is, of course, enough for some people to conclude to some massive Democrat conspiracy. What is the point for Democrats to do intimidation at polling stations in predominantly black neighborhoods? I have no clue, but logic doesn't seem to be required for these crazy conspiracy theories anyways.

And when jwenting says "no different really..", I have to point out the obvious false equivication here. This is not a "tit for tat" case. There is a massive difference between a few flimsy anecdotal occurrences of a "mean looking" guy at a polling station, and tens to hundreds of thousands of predominantly Democrat voters being disenfranchised by a crony company that admitted to its "error". Not to mention everything else on the …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

No, there is in general no risk of opening up your computer to malware by writing your own software.

First of all, most malware is either packaged with specific applications (e.g., tainted freeware, or pre-installed crapware) or it exploits a vulnerability in a specific application or platform (e.g., MS Office, flash, .NET, etc.).

There are some vicious viruses that infect everything, but they are rare, and your home-made software is no more vulnerable to them than any other program (i.e., basically, the only protection against those are in anti-virus software or anti-viral recovery media).

Secondly, the things that are really dangerous from a malware perspective are applications that straddle across safety boundaries of the operating system. In an operating system, there are boundaries like between user-space and kernel-space, or between different privileges levels of users (guest, user, admin, super-user, user-groups, etc..). The key to most viruses and malware is to find a crack in those boundaries to try and move "up" from a normal application execution environment (e.g., low-privilege user-space) to a more powerful environment (e.g., super-user / admin, or running kernel-space code). This is because that is the environment in which you can truly do some damage or be able to permanently "hide" the existence of the malware / virus.

So, when people try to diffuse malware or viruses, they will look for vulnerabilities (or exploits) that will allow them to make that move. This means that they need to target applications, frameworks, protocols or OS APIs that provide …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, as Schol-R-LEA said, it's all done in software, and it's mainly just a matter of characters. The reality is, a computer never has to convert numbers into a decimal representation unless it is about to display it on the screen for a human being to read it, and human beings read characters. So, this is really just about converting a number into a sequence of characters, which is something for software to do. There would be no point in having dedicated modules on the CPU for doing this kind of conversion because it would just waste valuable real-estate (room on the CPU). Binary-to-decimal conversion is never going to be performance-critical to the point of needing special circuitry for, that's simply because it's always in order to face a human beings, and human beings are infinitely slower than the code that generates those decimal characters.

At some point, as a programmer, you end up forgetting that decimal numbers even exist... because the only thing that matters is binary numbers (and base-2 floating-point numbers), and sometimes, their hexadecimal equivalent (which are much more natural to use in computing).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

When you have a compiled program, i.e., software, then that is just a chunk of memory containing machine codes (or instructions). So, as AD said, the thing that converts software (source) into binary form is the compiler. Once you have a binary executable program, the way that it gets executed on the processor is actually very simple (it has to be, it's just "dumb" electric circuits after all).

Each instruction is a sequence of 0s and 1s (bits), that is usually 32bits long (or more or less, depending on the architecture). Imagine that sequence of bits like a sequence of valve positions for a series of pipes bifurcations carrying water. If 0 is left and 1 is right, then you could have an instruction like 11001, which would mean to set: valve 1 = right, valve 2 = right, valve 3 = left, valve 4 = left, and valve 5 = right. That unique sequence of valve positions carries the water to a unique route through the pipes, to a unique destination. This is basically the way processors execute instructions, except that the "water" is made of electrons and the "valves" are transistors. That is probably the simplest way to picture it.

Complete instructions to the processor are usually composed of an instruction (e.g., "add", "subtract", "increment", etc.) and one or two operands that sit on registers, which are little storage units directly at the "entrance" of the processor. So, if you do an operation like "add R1, R2" (which …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

When you have corrupt politicians who contract the private companies run by their buddies to create voting systems without any kind of supervision or integrity checks on the software, then, yeah, this is exactly what you get.

I don't see this as an inherent problem with online or electronic voting systems. It's a consequence of a complete lack of checks and balances in the creation and use of those systems.

For example, with traditional voting (paper ballots), there are also many opportunities for rigging the system. This is why there are regulations, laws, standard procedures, and various checks and balances in the process to make sure to prevent or detect fowl play.

The problem with all the incidents you just mentioned is that the private companies were just contracted to create a voting software, and their products were exempt from any checking, and were just blindly trusted and applied. Obviously, as a crony corporatist fascist, by bribing a few politicians, you can award the contract to one of your companies and rig the software in favor of your favorite lap-dogs (the GOP) (as opposed to your less favorite lap-dogs, the Democrats, which are still your lap-dogs too).

People tend to make the mistake of thinking that "machines don't make mistakes", and therefore, there is no need for checks and balances on them. Many of us, being programmers, know how false this is. The way I see it, there are three main problems:

  1. The software (incl. submission protocols) could have bugs; …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Bush would still have won had there been a recount.

The problem with the 2000 Florida elections was not about the recount, but about the disenfranchisement of tens of thousands of primarily african-americans in Florida. This "error" won the election of Bush. And this "error" came from a private company who have since settled a lawsuit and effectively admitting to being responsible for the massive disenfranchisement that undoubtedly won the election for Bush.

And that issue was part of a coordinated afront on black votes, most likely coordinated by Bush's brother Jeb. Hard to prove, but very obviously so.

But this is 15 year-old news and not worth repeating.

Reminding people of the actions of criminals who conspired to overtly violate the US Constitution and take a piss on Democracy and everything Americans stand for.... yeah, that is worth repeating.

Reverend Jim commented: Very well put. +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

"Everything should be kept as simple as possible, but no simpler."

"If your code passes all your unit-tests, then your unit-tests are probably too simple."

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Animals are banned from mating publicly within 1,500 feet of a tavern, school, or place of worship.

Lol, this is especially dumb considering that human beings are animals too... "tavern", "school", "place of worship"... that's not even the kinkiest public places to mate!

Here are some stupid laws from my neck of the woods (Quebec, Canada):

Margarine producers can't make their margarine yellow.

Yeah, because it's really important that fake butter doesn't look too real.

It is illegal to curse in any language other than French.

Fuck! I broke that law! Send me to jail!

It is considered an offense to have more than two colors of paint on your house. (Beaconsfield )

Yeah... that should teach those hippies with all their colors..

You may not park a car in such a way that it is blocking your own driveway.

Want to park in your own driveway? No, you can't, 'cause that would block it! Park elsewhere... maybe your neighbor's driveway.

The Queen Elizabeth Hotel must feed your horse freely when you rent a room.

I sincerely hope someone tried to show up at that hotel with a horse and have it fed... the look on the hotel staff's faces would be priceless.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why would any colour show up in space?

That's right. Unless you are within a solar system, spacecrafts should be essentially invisible regardless of the color of their hull. And if you are within a solar system, the color white (or even more reflective, like MLI (or "aluminium foil")) is what you need to thermally shield yourself from the intense and direct exposure to the sun. In that way, the color white actually makes sense for spacecrafts like the Enterprise or whatever else, because within a solar system you need it, and outside, it doesn't matter what color you are.

For example, there are many "planets" (as in, large bodies of rock) that float around in cideral space, outside of any solar system. These "planets" can only be theoretically discussed (in terms of total gravitational effect, etc.) because there is absolutely not way to observe them because they are too much "in the dark", and thus, no light reflects off them.

your sensors would long ago have registered the ship anyway.

That's right. Although ships wouldn't have any light to reflect, they do emit radiation, that is, heat radiation from being "warm". This is not visible light, but certainly visible for sensors designed for it. In space, most things are really really hot, like stars, super-novas, gas giants and even planets, which means that they emit radiation that is far more energetic, including visible light (which require a body-temperature around 5000 Kelvin). So, if you calibrate …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The way I see it, if we can make online banking systems that we can trust (presumably), then we should be able to make an online voting system that we can trust.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Make sure you select "Console Application" in your project's configurations. The WinMain function that is missing from your code is the "main" function that is expected from a GUI Win32 application. If you select "console" application, it should be looking for the "main()" function, which I presume you have defined in your "main.c" file.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Daniweb has an API, see here. I don't know enough about this (both the API and your needs) to know if it will suffice, but that is one way to programmatically tap into Daniweb's database. I hope it helps.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Qt provides a very detailed guide on how to compile and use the static version of Qt. They even provide a fully automated PowerShell script to do it all. Is that what you tried? What was the specific problem?

configure static....

That looks more like a Unix-style command... are you sure you didn't follow the wrong instructions?

Maybe you followed this guide which seems more "primitive". That way of doing things is based on Makefiles and MinGW... which may require that you run the commands in MSYS, or, at least, make sure you have the correct PATH setup if using the basic command prompt (cmd.exe).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Like any other high-level interpreted language, Python is very good for dynamically putting together building blocks of an application. Virtually everything in Python that does anything substantial in terms of computations will be done within a native-code library through Python bindings. Those libraries are typically written in C and C++, and a few other specialized languages (e.g., Fortran for numerical stuff). Then, Python binding code is written such that you can call the library's functions or classes from Python. So, the real power of Python is that you can operate at this high-level space where all you can bring these various library components together. And Python is really good at that because of the way it handles objects and conversions, it just makes the whole process very easy and dynamic. That's really where Python shines, and where it should be used.

As an interpreted dynamic language, you can't really use it for anything that is computationally intensive. For that kind of tasks, you should write an implementation for that task in C / C++ or another similar high-performance language, and then create bindings to be able to call it from Python. As I said, that's how virtually all good Python libraries are created.

As far as what kind of games Python is good for making, there really isn't an answer to that. It's a general purpose language, and given what I explained above, it really depends on the libraries you have and that you can rely on. So, it's not …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't really know Ruby, and only a bit of Python (as much as I need). But I definitely say, go for Python. Python is great and is definitely becoming an landmark language in that space (high-level interpreted languages). I can't give you technical arguments why, all I can do is give you my impression, which is that Python is everywhere and super important, while Ruby remains obscure and seems to be "losing the fight".

Also, I don't know what you think that these languages will do for you in terms of game-dev, but I don't think it's much. Serious game-dev is dominated by C++. The "fun apps" space is a bit more diverse (Obj-C, Java, Python). But still, the primary focus for game-dev is C++, and it will remain so probably for a long time. And that brings me back to Python, one of the great advantages of Python is that it interacts very well with C/C++ libraries, and so, it's a great language to use as a high-level layer sitting on top of the serious heavy-lifting code that you write in C/C++.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't think that putting them in separate programs is really what you should do, because that's very weird (and could be challenging a bit).

I think that if you want to pursue your idea of the "24 items into 24 blocks of code", then you should create each item as a header / cpp-file duo (or more). Something like this:

"item1.hpp":

#ifndef MY_PROJECT_ITEM_1_HPP
#define MY_PROJECT_ITEM_1_HPP

void execute_item1();

#endif

"item1.cpp":

#include "item1.hpp"

void execute_item1() {
  // ... code for item 1 (e.g., like the "main()" of your item1 program).
};

"main.cpp":

#include "item1.hpp"
#include "item2.hpp"
#include "item3.hpp"
...

int main() {

  while(true) {
    int item_chosen = 0;
    std::cout << "Please enter item to execute: ";
    std::cin >> item_chosen;

    switch(item_chosen) {
      case 0:
        return 0;
      case 1:
        execute_item1();
        break;
      case 2:

      ...

      default:
        std::cerr << "Error, invalid choice!" << std::endl;
    };
  };

};

Then you just compile all your cpp files and linked them together. That's the "C++ way" of doing things.

Also, I would note that I doubt that your professor really just wants you to copy-paste your last 24 assignments into a single project. There isn't much "learning" involved in doing that. My guess is that he wants you to come up with a more complete and coherent project that happens to exercise all of your learned skills. That's just something to think about.