rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Linus Torvalds started hacking on minix, and then started his own OS - it was at least 2-3 years before it was released into the wild, and is now the most widely used OS in the world! :-) If you really want to do this, then I suggest tackling a more "advanced" architecture, such as a micro-kernel message passing OS. For reference material, see Thoth, Plan-9, QNX, Amiga OS.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Be careful of your math. This expression change * 1.85 + 2.50 will be interpreted as (change * 1.85) + 2.50. If you intended this change * (1.85 + 2.50) then that is NOT what you will get. So, make sure to properly bracket your math expressions, or you may not get the results you intended, and the satellite you launch may end up in the ocean instead of orbit... :-)

Also, you are not setting 'total' in your calculate() function. If you want to add the change to 'total' and return that, then this would be more appropriate, assuming the math is what you intended.

double calculate( double change )
{
   change = (change * 1.85) + 2.50;
   return total += change;
}
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

This may be a bit better (warning! untested code!)

#include <iostream>
 
using namespace std;
 
class ListNode {
 
public:
 
  double value;
  ListNode *next;
 
  ListNode* add( double );
 
  bool isMember( double );

};

// Add new member and return a pointer to it. 
ListNode* ListNode::add( double x )
{
    ListNode* newNode = new ListNode;  // Creates a new ListNode
    ListNode* pNext = 0;

    newNode->value = x; // Set value and clear next
    newNode->next = 0;

    // Seek end of list if this node is not there.
    for (pNext = this; pNext->next != 0; pNext = next)
    {
        // This loop only seeks to end of list.
    }
    pNext->next = newNode; // Now, link new element to end of list.
    return newNode;  // Finally, return new end node.
}
 
int main(void)
{
    const int SIZE = 5;

    double testValue[SIZE] = { 1, 3, 5, 7, 9 };

    ListNode *head;
    ListNode *curNode;

    head = new ListNode;  
    head->next = 0;
    head->value = testValue[0];
    curNode = head;

    for( int i = 1; i < SIZE; i++ )
    {
        curNode = curNode->add( testValue[i] );
    }

    // Walk the list, and print the values.
    for (curNode = head; curNode != 0; curNode = curNode->next)
    {
        cout<< curNode->value << endl;
    }
    return 0;
}

Just remember the KISS principle! :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

For something like this you would need a global map object that maps names with data, so your function could create the new object and add it with its name to the map which is the real global container of these objects. Then, create a function that allows you to do lookups by passing the name, getting the object back in return. You might want to implement this as a class, with accessor, destructor, and other such functions, so the global object would be an instance of this class.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Actually, no. Because of the order of construction, the rule is that all virtual base classes should be initialized before anything else. Since, in this case, a parameter is required to initialize the base class Person, all derived classes have to explicitly call the constructor of Person with a parameter (e.g. theName) in their initialization list. Basically, if you create an object of class Teacher (with two parameters: name and class), then the theName parameter will be carried over to initialize the Person base class. The same if you create an object of class Student. However, if you create an object of class TeachingStudent, in order to be able to construct its virtual base class before anything else, the constructor of Person has to be called with the proper parameter in the initialization list of TeachingStudent (this explains the addition of "Person(theName)" in your "confusing" line of code). When the other (non-virtual) base class constructors are invoked (for Teacher and Student), even though the theName parameter is given to them, it will not be carried over to the virtual base class Person, since that base class constructor was already invoked before the constructors of the non-virtual bases (Teacher and Student). And, of course, constructors are only invoked once and exactly once.

Good call. It has been so long since I did any virtual inheritance like this that I forgot the fact that the virtual base class (Person) needs to be initialized by the derived class which encompasses the other classes …

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Since Person is a virtual base class for both Teacher and Student, there is only one implementation in the TeachingStudent class, so even though Student and Teacher constructors are calling the Person constructor, they really are just setting the same name member in Person with the same data. Effectively, writing the member twice. Not a major issue here, but something to look out for in more complex scenarios. Dealing cleanly with virtual base classes is really gnarly at times, which is why I avoid it as much as possible. When I utilize multiple inheritance, I always make sure the base classes are 1) not virtual, and 2) don't have a common ancestor. There are other techniques to get the benefits of multiple virtual inheritance, that are generally safer, such as using the PImpl pattern (Pointer to Implementation).

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Well, the paper addresses the problem symbolically and algorithmically, so the language it is implemented is up to you, the implementer. However, network routing is done in the system kernel, and access to kernel structures from a user-space Java application may be difficult. Not necessarily impossible, or even necessary, but this is not a trivial exercise. Break the problem up into domains of behavior, and address each individually, with a view to the whole.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

The hardest? Probably the code I wrote that enables you to extend properties and behavior of C++ classes at runtime via specifications and rules, not coding. I got a patent for that. The software is used extensively in the semiconductor, flat-panel display, and disc drive manufacturing domains. It allows a manufacturing execution system to be tailored to the requirements of the customer without needing to write code. All the properties, behaviors, and rules are stored in the database, and loaded into memory when the application servers start up. Mostly, these are persistent object properties as well, so it also extended the classes' persistent attributes in the database (Oracle mostly), so when an object was stored, the new properties would be also.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

FWIW, the source for mount is in the util-linux package.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You can get source code from download mirrors for all distributions. You need to get the source that is used in your system for best compatibility. What distribution+version of Linux are you running, and on what platform?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

It may be due to some dust in your hard drive. It reduces the performance of the hard drive.

It is highly unlikely to be dust in the drive. It would already be dead if it were unsealed enough to allow dust particles into the drive assembly. On many drives there is a carbon electrode in the center of the drive hub that has a copper strip resting on it (spring loaded) to drain static charge buildup from the drive/platter assembly which would cause data be be lost. These sometimes start to make noise as the carbon and copper parts wear from friction. Usually, it just gets irritating, but I have never had this cause lost data. Usually, when it gets too irritating, I just replace the drive to keep my sanity.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

A stuck key can do this. Try booting with everything external (including keyboard and mouse) disconnected, except the monitor.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Missed that (no modulus operations)... Thanks! Naturally, modulus operations are basically "divide-by and test for remainder", and since divides are disallowed, that makes sense.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

By seed string and/or seed file, do you mean that you generate a hash from that and then use the hash to encrypt/decrypt the plain-text data?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You'll also need to utilize modulus operations to determine if there are "left over bits".

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Bitwise operations:

multiply by 2 == <<1
divide by 2 == >>1
add == +
subtract = -

So, if what I understand you to mean by "saturated" arithmetic, with limits of +-21474, then the problem becomes much more comprehensible. In any case, please clarify if I am making the appropriate assumptions. Your terminology is not what I have used in the past.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

It sounds like you are trying to generate a hash function - take arbitrary string (of any length), and convert it into a numerical (hexadecimal) value. Is that the case? If so, there are a number of hash functions that you can use as examples, such as md5, sha1, etc.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Disclaimer: I only have Intel processor systems, and my main workstation also has an Intel S5000XVN motherboard.

For processor price/performance trade-off, AMD is a better buy than Intel. They are both competitive in terms of performance these days, but AMD parts, especially at the higher-end, are significantly less expensive than Intel parts. There are good sites for product evaluations of boards and chips, such as Phoronix, that may be helpful for you to visit.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ok. This is a start. Give me a bit of time to analyze your code, in light of the requirements. Dinner time for me now... :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Ok. Fair enough. Do you know the way to do it manually, with calculations and graph paper? We can start with that, develop pseudo code, and then convert that to program code. The first thing is that you need to know how to solve the problem in its most basic form.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Have you verified that fopen() actually gives you a FILE*, and not NULL? If it cannot open the file, then the fscanf() function will cause a segfault. This is a good example why you REALLY want to test the results of functions such as fopen(), to verify that they were successful.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

It depends upon what you mean by "verify". You can create post-insert/pre-commit triggers on each field that needs verification so that your own code (rules) will "verify" that each field is valid before it will commit the record to disc. You can also apply these rules for updates as well. This is pretty standard relational database cruft. Mostly, it is a matter of writing the rules, and creating the triggers to apply them. That's mostly grunt work, but necessary for any significant database application.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Please try to be more specific (and detailed) on what you are trying to accomplish, and why.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

So, you want us to do your homework for you, and complain when we tell you to make some effort first on your own? What a maroon!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Well, without seeing the calling code and called code completely, this is hard to nail down. Until then, nothing is cast in concrete...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Yes, that would result in a problem. You need to change the hdrContent argument to be a char**, and pass the address that holds the pointer. Then, you probably also need to free the old memory. So, maybe something like this is appropriate:

if (hdrContent == 0)
{
    /* Error - invalid argument */
}
else if (*hdrContent != 0)
{
    free(*hdrContent);
}

*hdrContent = (char*)calloc((strlen(command)+strlen(data)+sizeof(bool))+4, sizeoof(char));
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

That's why we use it to run Billion$ semiconductor fabs, US Navy repair depots, stealth fighter avionics, highly sensitive medical devices, automobile manufacturing plants, space shuttle systems...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Well, without seeing what the rest of your code looks like, I can only make some uneducated guesses. One thing to look for is variable overloading. That is when you have a global variable defined somewhere, and yet somewhere else, in a header or in your source file, there is another variable of the same name. For example, if you declared/define a variable in your local translation unit, or local function, with the same name as an external global variable, the local one would take precedence and the global one would not be modified.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

As opposed to gets which also adds a terminating null character for you? :icon_rolleyes: The nice thing about fgets over gets is that it's possible to make fgets safe.

Yes, but as you pointed out before, it may be terminated in la-la land... Many moons ago (20 or so years) I was selected to be our company's first formal software quality manager - they even sent me off for a bunch of training. So, formulating our sqa policies, my team and I started formal testing of our manufacturing cell control software. Testing for buffer overflows and remediating them was our job for quite some time. The end result? Our software was tonnes more reliable, and our customers were a LOT happier with us. With the knowledge we gained, we were able to institute formal coding practices and code reviews for all code that would make it into the production system, looking specifically for such things as this. So, all applications did things like checking input arguments for length, type, boundary values, etc.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

I thought it sounded tricky. Didn't know it was NP-hard.

You'd have to generate hash values for every possible member of the set, and since the set is effectively infinite...

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

There are techniques for building a call-tree by judicious use of macros, so in your code you can do something like this:

#ifdef DEBUG
#define MAX_TREE_DEPTH 10000
size_t ct_level = 0;
const char* call_tree[MAX_TREE_DEPTH];

#define CALLTREE_ENTER call_tree[ct_level++] = __func__;
#define CALLTREE_EXIT  call_tree[ct_level--] = 0;
#else
#define CALLTREE_ENTER
#define CALLTREE_EXIT
#endif /* DEBUG */

void a(void)
{
#ifdef DEBUG
  printf("a() called from %s\n", call_tree[ct_level - 1]);
#endif
}


void b(void)
{
#ifdef DEBUG
  printf("b() called from %s\n", call_tree[ct_level - 1]);
#endif

  CALLTREE_ENTER
  a();
  CALLTREE_EXIT
}

int main(void)
{
   CALLTREE_ENTER
   b();
   CALLTREE_EXIT
   return 0;
}

Now, if you haven't compiled your code for debugging, this will have no performance impact upon you, but if you did, you get the call tree output.

I leave it as an exercise to the poster to add the macro needed so you can eliminate the #ifdef DEBUG blocks in the functions, so you could do something like this:

PRINT_CALLER(__func__);

instead if debugging is on.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

These are all definitions. A declaration would be an extern, such as

#include <stdio.h>

/* Declaration of foo being an integer */
extern int foo;

/* Definition of bar as an integer. It is still a definition
 * even if it hasn't been initialized.
 */
int bar;

int main(void)
{
   bar = foo; /* initialize bar with value contained by external variable foo */
   printf("%d\n", bar);
   return 0;
}

Notice that I did NOT initialize the variable bar before entering main. Until you get into main(), there is no way to know if other external variables have been properly initialized as yet. Caveat programmer!

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

One of the nice things about fgets() is that it deals with the terminating NUL byte for you, so you know that the string is properly terminated.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Your code to clear the contents of the hdrContent variable is wrong, and won't clear the entire allocated space. This is a case where calloc() is a better option than malloc(), as it allocates and clears the memory at the same time. The calloc() function takes two arguments: the first is the number of elements, and the second is the size of each element.

So, your allocation code would be something like this:

hdrContent = (char*)calloc((strlen(command)+strlen(data)+sizeof(bool))+4, sizeof(char));

Also, make sure you have allocated enough space for a terminating null byte.

n1csaf3 commented: This fixed future bugs in my code, thank-you. +1
rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

That's why there are TA's (Teaching Assistants) - to help the clueless get one! Do some googling or visit the library or wikipedia. Also, since you can get access to pseudo code for this, writing the program should be pretty simple.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

For software engineering, these are required reading

1. Niklaus Wirth: Algorithms + Data Structures = Programs, published by Prentice-Hall
2. Donald Knuth: The Art of Computer Programming, 4 volumes, published by Addison-Wesley

As for fundamentals of computer hardware, I don't know off hand what would be equivalent in depth to those above for software, but I know there is plenty of good material in the Wikipedia.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

You can generate a unique ID with 48 hex characters or less, effectively. There is no way to generate a guaranteed non-colliding hash value mathematically. It is one of those NP-Hard problems. So, generate a GUID, and forget hash values if a collision will indeed be "fatal".

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Answer C is correct, but it can also be expressed like this

!(A || B || C) == (!A && !B && !C)

Why? Well you could generate a set of truth tables (ever take formal logic?), or just think about it.

if (A is true) or (B is true) or (C is true), then (A or B or C) is true.
Apply negation operator NOT to (A or B or C) is saying "if NOT (A or B or C), then results is TRUE only if they ALL are FALSE".

More confused yet? :-)

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

One often ignored synchronization method is a message send/receive/reply. The receiver is the gatekeeper. One who wants access to the resource sends a message asking permission, if there are no others who have asked, the receiver replies, unblocking the sender who knows he has exclusive access to the resource. When done, he sends a "I'm done" message, and the receiver knows that the next sender can get the resource, doing a basic ACK reply. If more than one sender asks for the resource, they get queued, and blocked, until the resource is available. They can set timers so that if they are blocked for too long a period, they are broken out of the wait-for-reply state and can go on and do other stuff. This is how message-passing micro-kernel operating systems such as QNX, Plan-9, Thoth, and the Amiga OS work.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

We aren't here to do your homework for you! Please at least make an attempt at it first if you want any help... :-(

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

So, show how you solve this on paper. Then we can probably help you reflect that algorithm as pseudo code that you can fairly easily implement in a number of programming languages.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What jingda said, but you might also want to run a diagnostic on the system to see whether or not the lan adapter has died.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Roshki made some good points. As for controlling your bandwidth usage, most torrent clients have the ability to limit the number of uplinks that you will provide, reducing upload overhead by some factor. The entire idea of bittorrents is to distribute the load and bandwidth needed by many downloaders trying to get the same file, so as your system downloads chunks of the file, those become available for others to get from you. Since your upload speed is usually smaller than your download speed, too many connections will cause some congestion, hence the ability of most tools to limit this. However, bear in mind that if you limit upload access too severely, your download connections will become lesser as this balancing (the more you give, the more you get) is part of the bittorrent algorithm.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

What slots does your motherboard have? Usually they have 1 PCIe x16, 1 x4 (or an x16 that also supports x4), and some PCIe x1 slots, at least newer ones do. I'm not sure if you can use an x1 board in an x4 or x16 slot - probably not, but as some have slots that support both x16 and x4 cards, there are some x4 slots that also support x1 boards. My advice is to go to the motherboard manufacturer's web site and look at the board specifications.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Please post information about make/model of the motherboard, ram installed, CPU(s), video board, and also what other stuff you may have installed, then finally what is the capacity of the power supply.

From your description of the failure, it could be an inadequate power supply, incorrect memory, CPU or RAM overheating, using the wrong slot for the video board, or something else.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Try 3.4.4 - it works well with 2.6.21 Debian ARM kernels.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Gnome, and I think Compiz, use the GTK+ toolkit to build GUI apps and applets. You need to read the developer's documentation, available online from the gnome foundation.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Go to the board manufacturer's site for instructions how to write an operating system to it's flash memory, unless it can boot from network or SD card. In any case, each board differs, and you need the tools and or process documentation from the manufacturer.

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

Are you running the ftp client on Windows or Linux?

rubberman 1,355 Nearly a Posting Virtuoso Featured Poster

ffmpeg also has a server component, ffserver. You might want to check into that.