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

But I already do that! And its extremely easy to do with my method! Probably dramatically more so than any other way. I simply add a
#include “filename.test.cpp”
to my single everything.cpp file just after
#include “filename.cpp”
and I am instantly productive.
Even better I can change the entire configuration/implementations by just changing a few > template parameters!

Ishh... You actually have to modify code (by adding an include statement or changing a few template parameters) to add the unit-tests... that's very ugly, sorry. There are two common ways to setup unit-tests:

1) You put the "main()" function for the unit-test at the end of the cpp file containing the functions that are tested by the unit-test program, but you wrap that main() function with a compilation flag. As so:

// in a cpp-file:

#include "my_functions.h"

void foo() {
  //...
};

//... other function implementations.

#ifdef MY_LIB_COMPILING_UNIT_TESTS

int main() {
  //... all the unit test code.
  //... usually returns 0 for success and an error code otherwise.
};

#endif

2) You create a separate cpp-file for each unit-test and link it to your library.

The advantage of either of these methods is that you have no intrusion at all on your library's code itself. In order words, without changing anything in the code, you can seeminglessly compile all your code into static or shared libraries (and/or a set of executable applications) without leaving a trace of the unit-tests, and you can easily compile …

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

If this “careful method, with good interface designs and specifications, and comprehensive unit-tests, is a hugely useful and beneficial method” and if ¨there are rarely reasons to go back to the drawing table or to solve any difficult bug (there are always little typos and mistakes, but rarely anything serious)¨ how is it then that the biggest companies in the field (Microsoft, but I could also use other examples) isn't able to deliver on time its products, and even without such huge and significants bugs that it has, in the past, embarassingly crashed flagship presentation of their “new super-stable bug-free most-tested ever product in the world” ?

More recently in a previous discussion with Vanjiyan we came up with a bug in VC2009. I submitted the bug to Microsoft, they confirmed it. Surely, with the state-of-the-art techniques and seemingly perfect coding architecture you so eloquently described it should have been a breeze for a 73 billions annual revenue company to fix it giving that VC2009 is supposedly a flagship product? Wouldn't even a summer intern with such powerful tools you described been even able to suggest the fix himself? Well guess what: they respond it would be too difficult for them to fix and they would not fix it! So ciao, for that nice theory of easily repairable well-designed software!

Microsoft's coding practices are shameful, and have always been. They are primarily a marketing firm. If you read their internal communications, management has made it very clear that …

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

Here is a basic outline of how the vast majority of programmers work:

  1. Get an idea for a project, or be given a problem to solve from your boss or superior.
  2. Sit down alone or with your team to brainstorm / discuss / think about the best way to solve the problem.
  3. Draw diagrams to organize the specific parts will make up the code, understand the dependencies, split the responsibilities and sub-problems among the different parts of the code.
  4. Design the interfaces for the code, either alone or as a team, defining in a strict manner how each functions and classes will be used and what effects they will have (called post- and pre-conditions).
  5. Write header files which put these designed interfaces into concrete code in the form of class declarations, function declarations, and inclusion patterns.
  6. Split the implementation work among co-workers (or, on a lone project, split in terms of time (when you will do what part)).
  7. Work on implementing the interfaces you were given to implement, this goes into cpp files.
  8. Write a complete suite of unit-test programs to exercise and verify that all the functions implemented behave as required by the design specifications laid out in step 4. If tests do not pass, go back to step 7.
  9. Run a suite of integration tests to make sure that all the parts (written by you and your co-workers) interact as expected, if not, go back to either step 3 or 4.
  10. Deploy the product.
  11. ...

You see, …

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

To recall: I am not asking the moon:

No, you are not asking for the moon, but you are a bit too picky, you won't find an exact tool that does exactly what you ask for. But I guarantee that there are lots of tools that will satisfy all your needs once you get to know them. Remember that programmers often tend to prefer command-line tools, so, it's not always going to be plug-and-play, all bells and whistles tools like you seem to expect.

1) list the functions required by a file/function

I told you already, that's called a call-graph, see this example.

2) list all functions that are using my functions.

This is called a caller-graph, see doxygen instructions for CALL_GRAPH and CALLER_GRAPH.

Doxygen seems to be the tool you are looking for. But there are also many other tools that can either generate call/caller graphs or use such graphs for other purposes. For example, profilers like gprof or callgrind report their profiling results in the form of call-graphs (with execution times required by each).

One of the tool on the site, Graphviz, looked promising but it requires that you already have done one of my task (the reconcilisation of the function called with their definition) in order to run it.

Doxygen uses graphviz, like many other document-generation tools. Learn to use it.

KDevelop is probably useable on my Triskel/Ubuntu platforms but …

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

Here is a piece of code I wrote a little while ago (in response to a question about recursion) which incorporates a typical cross-platform switches in the code. Here it is:

#include <iostream>
#include <iomanip>

#ifdef WIN32

#include <windows.h>

static std::size_t get_stack_size() {
  MEMORY_BASIC_INFORMATION mbi;
  VirtualQuery(&mbi, &mbi, sizeof(mbi));
  VirtualQuery(mbi.AllocationBase, &mbi, sizeof(mbi));
  VirtualQuery((char*)mbi.BaseAddress + mbi.RegionSize, &mbi, sizeof(mbi));
  VirtualQuery((char*)mbi.BaseAddress + mbi.RegionSize, &mbi, sizeof(mbi));
  return mbi.RegionSize;
}; 

#else

#include <pthread.h>

static std::size_t get_stack_size() {
  std::size_t stacksize;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_getstacksize (&attr, &stacksize);
  return stacksize;
};

#endif

void print_countdown(int i) {
  int new_i = i - 1;
  std::cout << "\rCountdown to stack-overflow: " << std::setw(7) << new_i; std::cout.flush();
#ifdef WIN32
  Sleep(0);
#else
  usleep(0);
#endif
  print_countdown(new_i);
};


int main() {

  print_countdown(get_stack_size() / (8 * sizeof(std::size_t)));

  return 0;
};

You see how this is typically done when you really need to use OS-specific calls. In the above case, I was trying to extract the size of the stack for the current process, and the only way to do that is to call either a set of Win32 API functions or a set of POSIX-thread functions. Also notice how there is clearly no one-to-one correspondance between Win32 calls and POSIX calls, but you can usually do what you need to do in either.

To make it a bit better, you could also separate the OS specific code into separate source files.

Overall, you should try as much as you can to avoid having to do this. In fact, the above is the only time that …

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

Do i have to write two totally different codes for different enviroments.

If you stick to only standard libraries (I mean, the C++ standard libraries) and to standard C++, then all you have to do is recompile it for both environments. That's easier said than done for non-trivial codes, often you use non-standard features or libraries without even knowing that you do (some common ones are M_PI and C-functions from the global namespace (not in std::)), so it will just cause you to have to do some modifications to the code to make it compilable on both platforms at the same time. But, after that, the same code should compile on any platforms.

If you use external libraries (include GUI tools), then it depends on the compatility of those libraries. Most respectable libraries provide pretty good cross-platform support.

If you use native OS functions (such as Win32 API function in Windows, or POSIX functions in Unix/Linux/OSX), then you will have to provide different versions for the different target platform. Usually, this is done by wrapping all the platform-specific code into a somewhat isolated part of the code that can easily be swapped for another (one common trick is to have multiple folders, one for each platform, containing only the platform-specific codes and depending on the platform, you change the include/search directories when compiling the entire code-base).

If yes, is there anyway to MAP the code from one enviroment to another.

Not really, at least, …

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

^ Granpa Jim

What gets me mad is those lame vocaleses that most R&B singers always feel the need to do. You know, when the singer takes one syllable, stretches it out forever and makes a whole "melody" out of going between high and low pitch while on that same syllable. Christina Agulera is a pretty extreme example of singers doing that kind of thing. I hate that stuff, it's the best way to screw up a good song just to show that you have a "great voice". Being a good singer is not about having the greatest voice, look at Leonard Cohen, Marylin Manson, and others, it's about conveying emotions (which may or may not require a powerful / accurate voice), and about striking the right cords (not all the cords, in a chaotic vichyssoise of high and low pitch vocals). That's what grinds my gears ;)

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

To your original question:

Is it possible to 1) count 2) extract types in/from a typelist using variadic templates.

The easiest thing is to put the list of template arguments into a tuple type and then extract the count and elements. As so:

template <typename... Args>
struct info_on_types {
  static const std::size_t count = std::tuple_size< std::tuple< Args... > >::value;
  template <std::size_t I>
  using element = std::tuple_element< I, std::tuple< Args... > >::type; 
};

However, you can more easily get the number of arguments in the variadic template pack using the sizeof... operator. As so:

template <typename... Args>
struct info_on_types {
  static const std::size_t count = sizeof...(Args);
  //..
};

Very often, I must say, it is easier to deal with tuples instead of variadic templates. Except in cases of function with variable arguments or constructor-forwarding functions, it is easier to dump the variadic template pack into a tuple and then carry the tuple type around instead (under-the-hood). That's just a little tip, while I'm at it.

I tried with GNU G++ something like this but it didn't work.

This because you have a syntax error (enums are not integers). Try using a static const std::size_t as the type for the recursive "value" computation (instead of the enum), and it will work.

Now, to your second set of questions (in the future, please start a new thread when you have a completely new set of questions, trying to keep things organized):

1) List all …

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

I don't know if it counts, but there are a few good documentaries on hackers or the history of hacking. I quite enjoyed those, I think you can get them on youtube, if I remember, the australian one and the swedish one are pretty good, and I think there is also a BBC one.

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

Hard coded time = 125ms
PreCalced Array time = 130ms
PreCalced Vector time = 624ms
Repetitive Calc time = 5444ms...

First observation, from your code, my first thought was: the compiler will optimize away the entire calculation part of the hard-coded loop. And that's gonna happen even at lowest optimization level (as long as it is in release mode). In other words, it will come down to this:

double CalcHardCodedVAls()
{
    for (int iCount = 0; iCount < numberOfReps; ++iCount)
    {
        if (iCount % dotFrequency== 0)
        {
            cout << ".";
        }
    }
    double valReturn = 33.23 * .00195779856;
    cout << valReturn << endl;
    return valReturn;
}

In the case of the array storage, it is very likely to be similar, with the calculation line as double valReturn = 33.23 * arr[8];. Which means, in effect, that all you are really measuring is the time that it takes to do the dot printing, and that's why the results are identical. A simple way to test this is to remove the dot-printing and check if you get very close to 0ms (under the same compilation conditions). This is also why r0shi added the += in the loop instead of the straight assignment, this actually forces the compiler not to optimize away the loop.

The only reason why the vector case was much slower than the array case, is because the compiler cannot infer the same things about a vector as it can about an array, …

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

Like Wireshark. It's an open-source project, so feel free to check out its source code and learn from it.

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

cin (and other istreams) is a bit complicated to grasp at first, but here's the basic information you need to know:

cin is a buffer of data that accumulates whatever the user inputs, which it can then feed by various "extraction" methods. So, when the user writes something and then hits the enter-key, that data is placed on the buffer (internal to cin). When your program executes a line like cin >> userInput, the data is inspected (starting from the beginning of the buffer) for a floating-point value. It will skip meaningless characters like spaces, tabs, and new-lines, and will make sure there is a valid floating-point value there. If valid, it will set userInput to that value and will remove the extracted characters (skipped characters plus those making up the floating-point value) from the cin buffer. If invalid, it will leave the buffer intact and set an internal error flag (failbit to be precise). This sets cin into an error-state. When you evaluate it with !cin (or compounded as !(cin >> userInput)), it will be "true" if cin is in an error-state.

There are two things to notice. First, after one input failed, cin is in an error-state, which it will not "forget" on its own, you must tell it to forget about that error. This is what the function cin.clear() does, it tells cin to forget about its error-state. The second thing to notice is that extracting things from cin doesn't always extract everything from it. In fact, …

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

Most GUI tools will hide away the main() function, because you don't have to temper with it, shouldn't need to, and probably shouldn't, period. But if you want to know what it looks like or what it does, out of curiosity, I can tell you.

Typically, a GUI application is made up of two things: a main() function that creates the window, and an event-loop to handle messages relevant to that window. In Windows, the main() function is called WinMain() which replaces the main() function when compiling a Win32 application (as opposed to a "console" application). Usually, this function simply creates the window handle, attaches an event-processing function to it (i.e., a function pointer), starts the "execution" of the window (i.e., the window shows up and events start to get handled), and then it waits for it to be done (after you close the window). Usually, the WinMain() functions generated by typical GUI tools (like MFC, Qt, wxWidget, VCL, etc.) contain less than 10 lines of code. For example, this is a Qt main() function:

#include <QApplication>
#include <QTextEdit>

int main(int argv, char **args)
{
  QApplication app(argv, args);

  QTextEdit textEdit;
  textEdit.show();

  return app.exec();
}

The event processing is done via a call-back function, conventionally called WndProc(), which is registered to the OS as being the call-back for the created window handle. Basically, when you click anywhere on a window or push a key while in focus of that window, the OS creates …

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

1) Return-value-optimization (RVO):
The situation you describe is one of the basic applications of return-value-optimization. This is a classic optimization, permitted by C++, and implemented by all decent C++ compilers that I know of. You can check the assembly listings generated by your compiler for the given code to see what actual code it produces (if you do a lot of nano-optimization as you seem to imply, then you definitely need to learn to produce and read the assembly listings of your compiler).

Seems like this could be easily avoided through compiler in theory if syntax such as Vec4 c = a + b; was used.

Yes, the compiler can easily avoid the temporary in this case, and it will do so through RVO. Even for code like c = a + b;, RVO will apply as well, given certain conditions.

2) Plain-Old-Data types (POD types):
When types are very simple (C-struct like types), we usually call it a POD-type. If it meets a number of strict conditions, the compiler will also call it a POD-type and perform a number of more aggressive optimizations in that case. The conditions are basically that it should have a default everything (constructor, copy-constructor, copy-assignment, destructor), no virtual functions, and no non-POD data members. Essentially, this allows the compiler to assume that all creation, destruction and copy operations can be performed by trivial copying of the memory (like C-style memmove()). In other words, the compiler assumes there is no additional …

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

Digg isn't designed to be a news aggregator: It's designed to be a social bookmarking site where users submit interesting articles. Their entire rating system is based on the reputation of the user who submits the article in the first place.
For a programming-related site, check out Dzone.com if you're not already familiar with them. They are social bookmarking for programmers.

Sure. I guess they are not technically-speaking news aggregators, but the point is that they mostly feature a stream of user-submitted "heads-up" about certain interesting articles. And given the needing-to-attract-traffic nature of these sites, they need a constant feed of fresh articles, and thus, mostly end up featuring lists of news articles. The sites are reasonably good at doing what they do, and that's fine.

From my understanding of the OP's description, this is not at all what he means with his website idea. It sounds more like a site to gather and organize references (links) for given subjects and sub-subjects. With a system to search and browse subjects (as opposed to using keywords in a search engine), to contribute to and watch certain subject directories, and so on. As far as I can see, sites like Dzone, Digg, Diigo, Delicious, etc. do not do this.

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

Vista was caused by a BAC of 0.10 wasn't it?

Either that or mental retardation. Taking 6 years to produce this shameful piece of software must have involved some form of collective state of impaired judgement.

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

Isn't this just like the old-style Digg?

Digg, AFAIK, just aggregates news feeds and keeps scores. At least, I don't know that it does anything else, if it does, it hides it pretty well.

@jkon:
There seems to be a term for this kind of site, Social Bookmarking. It seems most sites for this are pretty aweful, or have disolved into sites exactly like Digg or more general website ranking/commenting sites.

Now that I think about it, the closest thing is probably Wikipedia. If you want to research a topic, you go to the wiki page for it, read through the info, and then start digging through the interesting links (citations) at the bottom. Of course, you could make a site that is less of an encyclopedia and more of a link collection per topic.

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

This sounds like a good idea. I'm not sure if there is something similar already.

Just a thought. This sounds very similar to YouTube's "suggestions" column, but for website links (URLs) instead of videos. What I mean is that this list of suggested "related" videos is most likely created from a combination of factors including a preference for other videos from the same user account, a basic "google-search" result from the video title, and probably traffic statistics (e.g., what other video many users tend to click on after watching the current video, and things like that). I see no reason why one couldn't create the same kind of system for the web as a whole, and it is very possible that google already does something similar under-the-hood of their search engine (because traffic statistics definitely come into play). But, as far as I am aware, there is no system like a side-bar or otherwise that lists suggestions of other links you might want to visit given the page you are currently on.

I think you are suggesting to also include more user control on the link associations. I can easily see the purpose of that. For example, as a user of that service, let's say I'm interested in Klingon linguistics, I could create a folder for that subject in my user account and list a few interesting links related to that topic. Then, an another Klingon enthusiast comes along, searches for that topic on the site and finds my folder …

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

Though I'm pretty uptight about not smoking near computers. The tar can really gum up a computer.

I never smoke near my computer (never inside the house), but, being a Linux user, my hard-drive is full of tar-balls anyway ;)

I always thought drinking beer did that :)

Drinking and coding is OK, as long as your blood alcohol content is below 0.08. And the GUIs will only look cooler to you, beer goggles I guess.

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

The above declares an object of class MyOtherClass.

myClass.MyFunction();

The above calls a member function called MyFunction() on the object called myClass.

MyOtherClass *myClass;

The above declares a pointer to an object of class MyOtherClass. In other words, the pointer can store the address in memory of an object of class MyOtherClass.

myClass->MyFunction();

The above calls a member function called MyFunction() on the object pointed to by the pointer myClass.

What I am finding difficult is how to call functions of a class from multiple other classes without creating new instances in each one.

What you need for this is to share the instance (object) between the different objects that need it. This can be done with pointers (or better, with a std::shared_ptr).

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

You have to use Windows' partition manager and locate the linux partitions (they should appear as having unknown format, and there should be at least two of them (root and swap) and possibly a third one (/home)). Then, you "delete" those partitions which will create some "free" space on the hard drive. At this point, you can either select that free space and create a new partition that uses it, or expand one of your current partitions (F:) to use up that free space.

If you have grub installed as the primary boot-loader (on the MBR), you probably should use BCDedit or EasyBCD to reinstall the Windows boot-loader.

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

It appears you just don't have gcc installed (code-blocks or geany or kdevelop will not install the compiler, they are only IDEs). Run this command:

$ sudo apt-get install build-essential
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Please define what you mean by "report generator". Or do you mean documentation generator, like doxygen?

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

"Antitrust" wasn't too bad either. But "Hackers" is the classic.

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

So, why this wouldn't work is because there could be some dependecies of this DLL that's present in probably another DLL?

No. It has nothing to do with the dependencies of the DLL, it has to do with the way the DLL code is packaged and what the import library contains (or doesn't contain). Let's do a quick review of the way these things are created and packaged:

To start, you have a bunch of cpp files (source files). Each cpp file is compiled separately (called the separate compilation model) as what is called a "translation unit" to create an object file (.o or .obj depending on compiler). An object file is a piece of compiled code, separated by functions (the code for each function). Each function is given a "symbol" (the name of the function, usually with some decoration or mangling) identifying the section of code that it corresponds to. In the compiled code in the object files, every function call that appears (except those that the compiler inlined) appears not as an actual function call instruction, but rather as a reference to the symbol of the function being called. So, each object file has a list of symbols that it defines (its functions) and a list of symbols (for each function) that it needs (you can obtain that list of defined and used symbols for a given object file by asking the linker for it).

A static library, or sometimes called an "archive" (in Unix lingo), …

myk45 commented: Thanks! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Statically linking the libraries into the executable is not a problem at all. However, you have to be careful about a few things.

First of all, if you have an external library that provides a DLL and an import library (.lib on Microsoft compilers, and .a on others) then you cannot use that library for statically linking to it. The "import library" is essentially a static library which acts as a thin layer of functions that perform the dynamic linking of the DLL file (when the executable starts), it basically loads / unloads the DLL and attaches the function pointers of the DLL to the functions in the executable. You cannot use that library to statically link the entire code of the DLL into your executable.

So, you first need to make sure that you have the static library that contains all the code of the DLL, i.e., a static version of the dynamic library. This static library must have been compiled from the source code of that external library, it cannot be obtained from the DLL. So, if that is not what you have, you must get it, if you can't get it, then tough luck, you have to use the DLL (and distribute it with your application).

Second, if the external library in question also has external dependencies of its own (could be system DLLs or other external library DLLs), then to perform the static linking to that external library, you also need to link to all its …

myk45 commented: Thanks for the nice explanation :) +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

To sooth me down after a bad day, usually anything from "The Doors", "Bob Marley", "Scandinavian Music Group", or "Metallica" is all I need. "Rammstein" is also pretty soothing.

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

I think the point is that personally believe that herb sutter isn't someone with special gift nor ability.

Don't go looking for people with "special gifts or abilities", cause you're just setting yourself up for disappointments. There are great people who deserve a lot of respect or admiration, but there are no super-humans. If you elevate some person to some kind of godly status, you're most likely to be disappointed eventually (when meeting or interacting with the person, or when you find out more things about him/her).

Alexandrescu - love him.

Love him too. He's a real template-kung-fu master and a clock-cycle hawk. But he isn't flawless either.

As a flip side of a coin - in my college, doctors (not all of them but some) who work as my tutors, know so little that sometimes I wonder what they really know.

I get a bit of that too (from the other perspective). Sometimes undergrads think that because you are their senior, you're supposed to know everything about every subject they question you on. Remember that knowledge is volatile and changing. I forgot at least half of the things I learned during undergrad courses, retained only the essentials, while I developed much deeper knowledge of only a few specific areas. Give your tutors a break, dude.

I think your expectations are unrealistic. I know cause I was like that too. My father is really knowledgeable, especially in history and politics, I grew up thinking …

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

You would probably be better off using an off-the-shelf library for that, like the Open Dynamics Engine (ODE). It's a simple but pretty solid engine for doing computer game physics realism (not for real simulations, of course). The basic idea with this is that you control your objects (characters, vehicles, projectiles, etc.) by specifying initial velocities and applying force to them (e.g., steering, thrust, etc.). Then, the physics engine takes care of the rest (realizing the motion). ODE has simple collision detection routines too, like primitive to primitive collisions (box-box, box-sphere, etc.). I don't think that it does 2D physics though, if that is what you need.

For doing "frame independent movement", it usually involves at least two threads of execution, one for rendering and one for physics simulations (or motion time-integration). The physics simulation is there to update the position (and orientation) of your models with time. The basis for this is ordinary differential equations (ODE) and numerical integration. First, given a system of rigid bodies (e.g., solid objects), there are laws of classical mechanics that help you to compute the acceleration (and angular acceleration) of a body given its state (position, orientation, velocity and angular velocity) and external forces applied to it (gravity, friction, thrusts, etc.), these are called the governing equations (and in rigid-body dynamics, the easiest form is the Newton-Euler Equations), and they are ordinary differential equations (usually). Collisions come in as a large impact force as two …

claywin commented: Wow! I've never heard of this before! This will get the job done and a few more, thanks! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, I personally believe that it's good to have some sort of a formal education.

I'm currently working towards a PhD, so you don't have to convince me of that. However, for computer programming jobs, there is often much less emphasis on formal education as there is on demonstrable skills and experiences. For example, I was once offered a job at a computer game company, they were asking me to abandon my bachelor degree that I had barely started, long story short, they recognized my programming skills and didn't care that I had no more than a high-school degree. This is not uncommon in tbat field. It doesn't mean that a formal education is not useful or valuable. Often, the saying goes "you learn more in your first two years of work than you did in your four years of college/university".

Secondly I saw a discussion between him and one guy from boost library in which herb seemed to have very little idea what he is talking about.

Everyone say stupid things or talk through their hats. Herb Sutter is not immune to that. It's very possible that he was talking too much about something he knew too little about, that happens all the time, especially with respectable figures of authority that get a certain free-pass while doing it. They shouldn't get a free-pass, but unfortunately they often do. All that said, you cannot discredit the person as a whole because of that either. For example, …

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

Does anyone know what his formal education is?

Does it really matter? Whatever he studied, it's probably obsolete today. His accomplishments are stupendous and his technical knowledge of C++ and programming in general can be matched by only a handful of people in the world. This completely dwarfs whatever educational background he has, that's probably why you'd have a hard time finding out about it. The field of computer programming is very much like that in general, people get judged by their contributions, their expertise and their skill, the educational background matters only as a means to acquire those skills, but you are not judged based on education.

As for the criticism on that link, Herb Sutter is just one man, and Microsoft is a big organization that never cared much for C++ (for many reasons, mostly marketing and vendor-lock-ins). You can't blaim him.

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

Who do you write news stories for?

For Daniweb (for one), check them out.

Maybe we can keep it as simple as that

Yeah, at least, I think so. As for good or bad, well, they are just good or bad.

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

Welcome!

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

So much confusion, you seem to have confused yourself too. Cracker and Black Hat Hacker are not synonymous at all.

The term Hacker (black or white or whatever) refers to someone with the technical skills and ingenuity required to deconstruct systems in order to find weaknesses in them which can be exploited for purposes other than those they were intented for (or normally permit). For hackers, their interests lie in developing the means, not so much the ends.

The term Cracker refers to someone who merely uses tools, codes or methods created by hackers to carry out their mischievous (or political) activities. Crackers are solely interested in their ends (goal), good or bad.

As for alternative names:

For cracker, I like the term lacker, as a combination of "lacking skills" and "wanna be hacker". That is especially appropriate if the person in question brags about being a hacker, then you can tell him, no, you're a lacker.

As for crackers that purely do mischievous acts (hijacking emails, stealing credit card numbers or other info, bricking computers, etc.), what's wrong with just calling them fuckers, assholes, mother fuckers or bastards, or any other term that daniweb's language filter will block.

As for hackers, I never understood the whole "black hat" or "white hat" thing, what's wrong with "good" and "bad", it's much shorter and to the point. Why not call them "good hackers" and "bad hackers"? And, as far as I know, "bad hackers" (not crackers) are so rare that you …

happygeek commented: yep +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It's probably borrowed from the chain-smoking poet or whiskey-drinking writer stereotype.

Btw, I'm a programmer, a smoker, and a whiskey drinker, so I guess I qualify.

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

In C++, you need to do the cast explicitly:

static unsigned char row[4];
static unsigned short *p1 = reinterpret_cast<unsigned short *>(&row[0]);
static unsigned short *p2 = reinterpret_cast<unsigned short *>(&row[2]);
static unsigned long *long_random = reinterpret_cast<unsigned long *>(&row[0]);

That should solve your problem.

misi commented: Bullseye! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Look at this list of C++ operators, it shows all the operators (binary and unary) in C++ along with the prototypes for the member and non-member version of the operator overload functions. That might be a quicker reference for you than asking us for each operator.

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

I don't think that Dani submitted anything, at least, not that I could see when reviewing. So, she can't win.

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

The problem is that your function overload:

template<typename T>
void MemDeSerialize(T*& Destination, unsigned char* &Source, size_t Size){...}

takes a reference to a pointer. And because you call it with &Destination[I], which creates a pointer to the Ith element, that pointer is a temporary object, and it cannot be bound to a reference (only lvalues can bind to non-const references). In this case, there is no reason to take the pointer by reference, so, you can fix your problem with this:

template<typename T>
void MemDeSerialize(T* Destination, unsigned char* &Source, size_t Size){...}

Notice the lack of the & symbol. This should allow you to call the function with MemDeSerialize(&Destination[I], Source, 1);.

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

I personally prefer KDE. It is nice, polished and highly customizable (based on Qt). And the default configuration is very Windows-like, so it will be easy to adopt if that is where you are coming from. You can get KDE-packaged Linux distributions mainly as Kubuntu (based on Ubuntu), Fedora KDE Spin, OpenSUSE, Arch Linux and Linux Mint. I would recommend either Kubuntu or Fedora 17 (and, as of lately, I had a few bad experiences with the latest versions of Ubuntu-based distros (a bit unstable, buggy), so you might prefer Fedora 17).

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

Yup, and neither is *nix.

That's true for most *nix variants (at least, desktop / server operating systems), but remember that *nix variants is a very wide family, and almost all real-time operating systems are *nix variants, like QNX, LynxOS, VxWorks, FreeRTOS, and certain special versions of Linux (e.g., RTLinux). There are some slap-on frameworks for doing hard-real-time on Windows, but they effectively shutdown Windows kernel activity and replace it with their own kernel, which is often a posix-compliant micro-kernel. And yes, those cost quite a bit of money, because they usually involve strict quality and determinism guarantees.

But again, to make it clear, all my points about latencies and wait times on Windows apply, for the most part, exactly the same for all other generic desktop operating systems. Server versions have the same problem, but I think they are faster (software interrupts are clocked faster). And, of course, the actual latency / response times will vary between the different operating systems. But I know that desktop Linux versions (at least, those I have worked with, Ubuntu, Red Hat and SUSE) are clocked to achieve sub-millisecond resolution on sleeping / timing / wake-ups, since I have run up to 4 kHz multi-threaded apps (with thread synchros) on Linux kernels, so, in my experience, the resolution is at least down to the 100 to 50 micro-second range. But, of course, the same problems apply (not hard-real-time systems), but at one or two orders of magnitude higher time-resolution.

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

For the first thread, in Community Feedback, I believe it is normal as posts under the Community Center forums do not receive rep-points, that's just the policy. As for the second thread, I don't know why it didn't cause rep-points to the member. I have noticed something similar if you look at my latest post-comments given by triumphost. I don't know if it is a glitch of the system or some issue of when / how you hover / comment / click the arrow-up.

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

Sorry, but that's a horrible suggestion as it consumes all the cpu time leaving little or mnothing for other windows programs.

Yes you are correct, it is horrible, but the operating systems doesn't give you a choice if you want to sleep for a time-interval below 10ms or so, because that is basically the resolution of the Sleep function. Using timers can get you closer to a few millisecond resolution for a nearly-constant refresh rate (or frame rate) on calling a call-back function. For anything below that, as the OP is asking, your only choice is to have a tight loop (and possibly with an atomic lock if you can) because as soon as you use a Sleep or timer function you have to relinquish thread time to the thread scheduler with a software-level wake-up interrupt which has a minimum latency of at least a few milliseconds. For precise timing operations (down to tens of kilo-hertz resolution, i.e., 100 to 10 micro-seconds), you need a hard-real-time system, and Windows is not designed for that at all.

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

The "delay" function is called Sleep() and you can get it through the <windows.h> header. The Sleep function sleeps for the specified number of milliseconds. However, do not expect good precision, thread-switching frequency in Windows is notoriously slow and unresponsive, don't expect precision higher than about 10ms to 30ms.

The other solution is to use the clock() function in a tight loop. As so:

#include <ctime>

void delay_us(std::clock_t us_interval) {
  std::clock_t end_time = clock() + (us_interval * CLOCKS_PER_SEC) / 1000000;
  while( clock() < end_time ) ;
};
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I should look into it if it is possible to do quick operation to do merging and combining the same time the equal powers. But simplification also takes care of droping the 0 multiplier terms and it uses the C-speed sorting (minus the penalty of comparision operations defined in user class) which I would expect to not cause much penalty with typically less than 100 term polynomials case.

It is the same operation as you do when doing merge-sort, plus the "remove zeros" and "fuse equal exponent terms" parts which can be trivially inserted into the merge operation. My Python skills are too shameful to demonstrate it, but if something is trivial (<10 lines) in C/C++, I would presume it is even simpler in Python.

Currently, your "simplify" function has the following complexity. Assume the polynomial has N terms, the sorting takes O(NlogN) while your pruning+fusion of terms takes O(N^2) (because of the inefficient use of random-accesses in a sequential container), but of course, of implemented correctly, the pruning-fusion would have O(N) complexity. So, if A is the cost of comparing/swapping elements, and B is the cost of checking the pruning condition, then you time consumption is A * N * logN + B * N + O(1). If you use a merge-while-pruning approach, the overall time consumption will be (A + B) * N + O(1). If N is 100, you would roughly get 700 * A + 100 * B for the "simplify" approach, and about …

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

You can make a very simple serializer like this: (warning: this is neither robust nor usable as is, at least, not to my standards)

#include <fstream>

class iserializer {
  private:
    std::ifstream in_file;
  public:

    iserializer(const std::string& aFileName) : in_file(aFileName.c_str(), std::ios_base::binary) { };

    template <typename T>
    friend
    iserializer& operator >>(iserializer& in_serial, T& value) {
      in_serial.in_file.read((char*)&value, sizeof(T));
      return in_serial;
    };
};

template <typename T, typename Allocator>
iserializer& operator >>(iserializer& in_serial, std::vector<T,Allocator>& value) {
  typedef typename std::vector<T,Allocator>::size_type SizeType;
  SizeType sz;
  in_serial >> sz;
  value.reserve(sz);
  for(SizeType i = 0; i < sz; ++i) {
    T tmp = T();
    in_serial >> tmp;
    value.push_back(tmp);
  };
  return in_serial;
};

template <typename T, typename Allocator>
iserializer& operator >>(iserializer& in_serial, std::list<T,Allocator>& value) {
  typedef typename std::list<T,Allocator>::size_type SizeType;
  SizeType sz;
  in_serial >> sz;
  for(SizeType i = 0; i < sz; ++i) {
    T tmp = T();
    in_serial >> tmp;
    value.push_back(tmp);
  };
  return in_serial;
};

class oserializer {
  private:
    std::ofstream out_file;
  public:

    oserializer(const std::string& aFileName) : out_file(aFileName.c_str(), std::ios_base::binary) { };

    template <typename T>
    friend
    oserializer& operator <<(oserializer& out_serial, const T& value) {
      out_serial.out_file.write((const char*)&value, sizeof(T));
      return out_serial;
    };
};

template <typename T, typename Allocator>
oserializer& operator <<(oserializer& out_serial, const std::vector<T,Allocator>& value) {
  typedef typename std::vector<T,Allocator>::const_iterator Iter;
  out_serial << value.size();
  for(Iter it = value.begin(); it != value.end(); ++it)
    out_serial << (*it);
  return out_serial;
};

template <typename T, typename Allocator>
oserializer& operator <<(oserializer& out_serial, const std::list<T,Allocator>& value) {
  typedef typename std::list<T,Allocator>::const_iterator Iter;
  out_serial << value.size();
  for(Iter it = value.begin(); it != value.end(); ++it)
    out_serial << (*it);
  return out_serial;
};

Then, your custom …

triumphost commented: I solved it earlier but this is good! I'll try this on memory. =] +6
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I just cast my votes. And, of course, I didn't vote for my own snippet, even though it is clearly the best ;) (shameless plug)

I don't think the analogy with an election makes any sense. In an election, you choose the person or party that you would most like to see in charge of things, because of what you think/hope they will do once in office, or because he/she/they represent your positions / opinions / world-view. In case of elections, clearly, you should vote for yourself if you're a candidate. However, in this kind of a contest, the idea is to try to judge the work that has been done using your expertise and objective appreciation for its merits. Voting for yourself (at least, if you are voting just to give you a better chance of winning) is not OK in my opinion because it is neither objective nor based on your expert opinion, and it doesn't judge the work that has been done. This is the same reason that if you had a judge on an olympic competition (diving, acrobatics, etc.) who would automatically give 10/10 to every athlete from his country regardless of the performance, you would call that out as being dishonest and biased, because he is supposed to be impartial. So, even though I think my snippet is objectively part of the top contenders, and even if I probably would vote for it if it was written by someone else, I consider it …

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

First of all, you should not use template specialization of function templates. Here is an explanation why. You must use overloading instead. So, your "Model" Serialize function should just be a straight overload:

void Serialize(unsigned char* &Destination, const Model& M) {
    Serialize(Destination, M.SX);
    Serialize(Destination, M.SY);
    Serialize(Destination, M.Stride);
    Serialize(Destination, M.ID);
    Serialize(Destination, M.TriangleCount);
    Serialize(Destination, M.Vertices);
};

Second, when doing serialization, you will need more complexity than that because you'll have trouble with more complex cases. Usually, one would create a "serializer" class (and possibly a separate input and output serializer class) that acts pretty much like iostreams in standard C++ libraries. In the same way as you can make you classes (or structs) outputtable and inputtable to and from a standard iostream object (by overloading the << and >> operators), you do the same for your serialization code.

The general idea when doing serialization is that the mechanism for deserializing should be the exact opposite of the process of serializing. It is also a good idea, generally, to allow for more flexibility in the destination of the serialization such that you can use the same serialize/deserialize code for many purposes, such as saving/loading in files (of different formats), sending/receiving objects across a network, or sharing data between DLLs (modules). I suggest you take a look at some of the existing serialization libraries and get inspiration from that. Two examples I can think of are Boost.Serialization and my own serialization library (part of a bigger …

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

Of course, my C++-brain cringes at the sight of all the blantant inefficiencies in the code, but if I adopt the Python mindset, then your code snippet is quite nice! Lots of demonstrations of Python-kung-fu in there.

A few comments:

I think you are not protective enough of your invariants, and you suffer from constantly breaking and repairing them. By invariants, I mean the fact that a Polynomial is always a list of terms, in a sorted order, with unique exponents only. Basically, what the "simplify" function enforces. Many of your operations on the Polynomial, like addition, substraction, multiplication, power, etc. can all be performed entirely without breaking the invariants. For example, your addition function chains the two lists of terms, which creates a "polynomial" list whose invariants are broken, and then you repair it with "simplify". You are not taking advantage of the fact that your two input Polynomials contain sorted unique-exponent terms. You could "merge" the two Polynomials very easily, resulting in another Polynomial with valid invariants, without having the "simplify" it afterwards. The whole point of having invariants in a class and protecting them through encapsulation is to be able to avoid having to constantly check or repair the invariants, and to be able to simplify operations by relying on the invariants being respected on the operands. Consider that in the future.

It would have been a lot nicer if your test program was written in easier terms by using the DSEL that you just created (DSEL: …

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

Two DLLs loaded like that will reside in separate address spaces. You cannot exchange pointers or any pointer-containing object (like std::vector or your Model struct) between them through a mapped file. If you put a pointer address in a mapped file from DLL-A, and try to retrieve it from DLL-B, the pointer that DLL-B obtains will be completely useless because it is a pointer into DLL-A's address space, and is thus completely meaningless in DLL-B's address space.

To send this kind of information, you'll have to send the information in its entirety, not a pointer to it. In other words, you need to copy the information that the pointers point to into the mapped file, and then reconstruct it all in DLL-B.