deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually, this range only applies to 16-bit compilers such as Turbo C.

Incorrect. That range is the guaranteed minimum specified in the language standard, and it applies to all compilers. You're free to expect a larger range than that, but then you'd be depending on the compiler rather than the standard.

If you assume that int is 32 bits, for example, your code is technically not portable. If you assume that int is 16-bits two's complement (ie. you get an extra step on the negative range), your code is technically not portable.

The advice to jump from int to long when exceeding the range of [-32767,+32767] is spot on.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are two different things here, I think.

  1. Votes: These are the actual point values that contribute to your total up and total down vote counts.
  2. Currently positive or negative posts: These are lists of posts that are currently positive or negative when all votes on the post are taken into account.

If a post that's negative at -1 gets a positive vote, the value becomes 0 and the post is removed from the negative posts list. However, the downvote that put it on the list in the first place isn't deleted; that record remains in the database and still applies to both the post in question and your totals.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How should i decide which integer type to use?

When in doubt, use int. If int doesn't have the range you need or if you have special needs (eg. heavily restricted memory) that justify a smaller integer type, use something different. Over time you'll get a feel for which integer type to use in certain situations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For assembly I've always preferred OllyDbg. However, I've never run it through an IDE, always separately in its own UI. In fact, I've never used an IDE for assembly code that wasn't embedded in C or C++... ;p

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I answered my own question :D

Technically that's not the correct answer to your question, though it's close. Your question was how to extract "sample.xls", not "sample". In that case you need Path.GetFileName(). ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Include the implementation of the class in the header file too. Without getting into excessive detail, template classes and member function definitions aren't split across multiple files.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Er, not exactly.

True, but I'd question your sanity if you thought my brief confirmation of the general concept was anything remotely close to an "exact" description of what typically happens. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Both your solutions are not as good as using the os api.

I'm aware of that.

Both your functions are CPU hogs.

I'm aware of that too. However, the point was not to come up with the best possible solution for waiting a number of seconds. The point was to show that the time library needn't be so awkward. The library is awkward enough without actively choosing a backassward method of getting the information you need.

This understanding will help with problems that cannot or should not be solved with an OS API for the given problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What do you suggest?

NASM or FASM. Those are my favorites, though I've been known to enjoy the novelty of RosASM despite my personal feelings toward Betov and HLA despite its decidedly high level taste.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To avoid having to read all of your code (laziness on my part, most assuredly), I'll just point out that your Wait_Secs() function is needlessly complex. It can be as simple as this if you make an assumption that time_t represents seconds (not an unreasonable assumption):

void Wait_Secs(int seconds)
{
    time_t start = time(NULL);

    while (time(NULL) < (start + seconds))
        ;
}

A better solution depends on difftime() which actually does return a guaranteed number of seconds and is no less simple in my opinion:

void Wait_Secs(int seconds)
{
    time_t start = time(NULL);

    while (difftime(time(NULL), start) < seconds)
        ;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

However when I look through disassemblies of pretty much any program I notice that all such library calls are gone.

Those calls are hidden in the disassembly because you're looking at direct jumps into the libraries rather than the calls an assembly programmer would write.

A) Did the assembler simply copy-paste the library code in (like a header file in c/c++)

If it was a statically linked library, yes.

B) Where can I learn general assembly?

I think you're asking the wrong question. You seem to want to know how to write bare metal assembly, where you use OS interrupts to handle the lowest level of I/O and system calls rather than depending on existing libraries (such as used by Narue's tutorial). Personally, I think that's kind of dumb for the same reason you'd use the available printf() in C instead of writing it yourself.

As far as general assembly, any book on assembly language should cover what you need. Just go to the bookstore and flip through them to see which one you mesh with best.

C) I noticed that pretty much every tutorial uses different layout (IE: data:code: vs section data, etc) what are these and how can I know which one is correct?

Every assembly language dialect has a different syntax. That has nothing to do with assembly and everything to do with your particular assembler. Just read the documentation to get a feel for how it works and …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As I understand, you're trying to use the file as a random access collection, is that correct?

If that's so, I'd recommend writing a completely separate utility class for handling the file access through a more convenient interface. Something like this (written in haste, so there's probably plenty of useful member functions missing):

class RandomAccessFile {
public:
    RandomAccessFile(string filename);

    // Accessors
    int LineCount();
    string GetLine(int index);

    // Modifiers
    bool AddLineBefore(const string& line, int index);
    bool AddLineAfter(const string& line, int index);
};

The reason I suggest that is the file handling code is verbose and tedious. You'll also notice that it's slow as molasses because sequential files aren't meant to be used that way and file handling is one of the slower tasks one can perform in general.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then either the car is still traveling

Nope, the question clearly states that the car traveled (past tense) from A to B (a complete trip).

or it jumped part of the distance?

Or the person asking this question is math impaired? I still think that the most rational answer is 72km/hour and a broken odometer. How else would a car travel 36km and only report traveling 28km?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Great, now print out the contents of buf2 after read() and see if it contains the data you expected. I'm still willing to bet that it doesn't.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

needs to be a input output text file, its part of my requirments

That doesn't preclude you from also storing the data you need in memory. Load the file into memory, use it in memory, and save it back periodically or upon request. This is how most software that persists data in files works.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when you use read in your code, your program stops to take input from user

I'm well aware of what read() does.

i set fd and fd2 to zero but still does n't work

fd is set by open(), but fd2 is uninitialized in the code you've provided. Unless your compiler gives it a default value of 0 (some do, but most don't), that means you're telling read() to read from a garbage file descriptor.

What exactly do you mean by "doesn't work"? Print out the contents of buf2 after read() and see if it contains the data you want. I'm willing to bet that it doesn't.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The speed of the car was 72km/hour, and the odometer is broken. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code isn't retrieving anything from the command line; argv and argc are unused.

However, I'm not surprised at all that it doesn't work, given that you haven't initialized fd2 to anything. Presumably you wanted to read the "address" from stdin rather than command line parameters, in which case fd2 should be set to 0 (or ideally STDIN_FILENO if you've included <unistd.h>).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What I was trying to say is that when a forum member wants to endorse someone, that particular someone should have a minimum of 'X' number of up-votes in that forum.

Ah, I got it backward. But my example can be reversed too. If Bjarne Stroustup joined, I'd make a beeline to endorse him for C++, regardless of how many up votes he had. ;p

That say, there's a restriction on how many posts you need in a forum before that forum becomes a favorite, and it's based on a percentage of total posts. It's not a very severe restriction (only 2% presently), but that does provide at least a little bit of buffer for the member to earn enough respect for endorsements.

~s.o.s~ commented: Someone really loves Bjarne ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Not until you specify what kind of example you need.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could provide a little utility to your testers that grabs the image runtime version:

using System;
using System.Reflection;
using System.Windows.Forms;

class Program
{
    [STAThread]
    static void Main()
    {
        using (var dlg = new OpenFileDialog())
        {
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Console.WriteLine(
                        "Assembly Runtime Version: {0}",
                        Assembly.LoadFile(dlg.FileName).ImageRuntimeVersion);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                }
            }
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm so used to navigating directly to the specific forums I forget those even exist.

Prior to the current system, you couldn't post directly to the categories, which I think is a big part of the confusion.

should be interesting to see how this pans out. :)

Yup. I'm hoping it works out. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For example I never post in the Java forum so I would not be eligible to receive endorsements in that forum.

If you've never posted in a forum, you cannot be endorsed for that forum. The list is based on favorite places to post as shown on your profile overview. However, if you make even one post in a forum, that shouldn't preclude allowing people to endorse you if they feel you showed expertise deserving of an endorsement in that single post.

I would say make that "X number of up-votes" in a particular forum.

A counter argument is that you're making one subjective metric dependent on another subjective metric, which makes the metric no less subjective. While I don't disagree with such a restriction, it does encourage an old boys club mentality wherein only established members' opinions have any value. If Bjarne Stroustup himself joined and wanted to endorse me for C++ but couldn't because he didn't have enough up votes, I'd be a little miffed. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try to swap "Unchecked weight gain" and "Low testosterone"...

As much as I try, that whole cause and effect thing gets in the way. I find it hard to believe that weight gain would have caused low testosterone when the diagnosis of low testosterone came long before the weight gain. And there's no doubt that some of the weight is due to inactivity from fatigue, but he wasn't exactly a hummingbird in terms of activity prior to when all of the symptoms started to manifest.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I remember some time ago you had a list of file types that could be uploaded on the site, I can't see that anymore, why has it been removed?

I strongly doubt it was removed, given that we don't delete threads unless they're essentially pure crap that violate the rules. However, in response to a recent question I posted the supported file types, sizes, and image resolutions for both attachments and avatars:

http://www.daniweb.com/community-center/daniweb-community-feedback/threads/454229/max-sizes-on-upload#post1972372

.java files are included in that list. I assume you're trying to upload an attachment; what problems are you having, exactly?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

NOW THE QUES IS THAT I CAN'T UNDERSTAND

Which part don't you understand? The instructions are very explicit, though there's an assumption that you'll figure out how to calculate the distance between two points. I would expect a programming instructor to at least remind the class that the distance between two points can be solved with an equivalence of the Pythagorean theorem:

double a = a.getX() - b.getX();
double b = a.getY() - b.getY();
double c = sqrt(a * a + b * b);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can castration really prolong a man's life?

No, most certainly not. How am I so sure? For the last 6 years or so my best friend has been suffering from a number of negative side effects due to hideously low testosterone (he's only 33) including but not limited to:

  • Osteopenia bordering on osteoporosis
  • High cholesterol
  • Unchecked weight gain
  • Muscle atrophy
  • Intense fatigue
  • Insomnia
  • Vertigo
  • Weakened immune system

None of these are conducive to a prolonged life.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One shouldn't expect people to consistently vote on every post one makes, it's really all about who sees it, what their opinion is, and if their opinion is strong enough at the time to make a vote. Further, votes are completely subjective and not restricted to any guidelines (barring personal guidelines the individual voter chooses to follow).

However, it's important to recognize that your votes will trend over time depending on your actual post quality. Those with consistently good quality posts will have an amortized good vote rating, and those with consistently bad quality posts will have an amortized bad rating. For people who fluctuate, the votes should even out over time between positive and negative. If a member is active in the community for a number of months or longer, their overall trend should be reasonably accurate.

Ultimately we all get votes we think weren't fair, but all of these metrics are really just for e-peen points. What really matters is your intangible reputation among the community. There are no numbers for that, it's strictly what everyone thinks about you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm wondering where people go to get the basic knowledge needed to understand all about makefiles and their uses and how they work.

Make is a domain specific language, people learn it the way they would any other language: by reading documentation, books, tutorials, and maybe even watching videos.

The structured process of a book is the kind of approach I'm looking for.

Then get a book, they've been written on Make. Here are two relatively recent ones:

http://www.amazon.com/Managing-Projects-Make-Nutshell-Handbooks/dp/0596006101

http://www.amazon.com/GNU-Make-Program-Directed-Compilation/dp/1882114825

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An abstract class is meant to be used exclusively as a base class. In other words, it cannot be instantiated directly, but classes that derive from it (if not also abstract classes) can be instantiated. An abstract method is the same thing at the method level: there's no method body, and it's intended to be implemented in a derived class.

In C++ an abstract method is created with the pure virtual syntax, and an abstract class is defined as any class that has one or more pure virtual member functions:

class Abstract
{
    void foo() = 0; // An abstract method makes the class abstract
};

The above might also be called an interface because it only defines abstract methods.

p.s. I'm answering this in good faith, despite your previous posts following a pattern of signature spammers. That is, posting topical but largely fluff questions and answers, then applying a spammy signature to one's account after accumulating a number of such posts. Note that I'll be keeping an eye on you. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Database servers will provide a way to query the current ID. For example, in SQL Server you'd select one of the following:

select scope_identity();         -- Last identity generated explicitly in your scope
select ident_current('MyTable'); -- Last identity generated for the specified table

For MySql you might use something like this:

select last_insert_id();
select last_insert_id('MyTable');

Any programming API that supports database access should also provide a convenient (sometimes not so convenient) way of grabbing identities.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the max file size on uploads?

  • Avatars: 500KB
  • Attachments: 1024KB

What is the max size width/height?

  • Avatars: 640x480 for upload, but they'll always be reduced to 80x80
  • Attachments: 1600x1200

What file types are supported?

  • Avatars: GIF, JPEG, and PNG
  • Attachments: Image types are BMP, GIF, JPEG, and PNG. Non-image types are C, CPP, DOC, DOCX, HTML, Java, Javascript, PDF, PHP, PSD, RTF, SWF, TXT, Excel, XML, and ZIP.

Should say when trying to upload a file...

Common sense applies. If you feel any of our size/dimension/type restrictions are unreasonable, feel free to voice your opinion on what should be supported.

It all depends upon what YOU would like it to be.

This is the community feedback forum, not one of the web development forums.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Too bad C and C++ don't have that.

C++11 supports raw string literals that accomplish the same goal.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You neglected to post any of your code and failed to ask a question.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, the answer to your problem (but not to your question) is to change your IDE. Dev-C++ is far too old to support C++11.

The compiler can be changed to point to a newer version of MinGW. The only issue is there's no direct support for new features in the editor or UI components for C++11 switches in the IDE's configuration. However, you can still use the advanced command line arguments in the configuration to set those switches.

In other words, you can use a C++11 compliant compiler with Dev-C++, it's just not as easy as point and click out of the box. I agree that a newer IDE should be used, but some people like Dev-C++ too much to dump it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Perhaps the user on the server does not have priviliges to modify the registry.

An exception should be thrown in that case, but you can verify permissions without much difficulty using the RegistryPermission class. Here's a helper class that does the grunt work (for cleanliness):

using System.Security;
using System.Security.Permissions;

public static class RegistryInfo
{
    public static bool HasAccess(RegistryPermissionAccess accessLevel, string key)
    {
        try
        {
            new RegistryPermission(accessLevel, key).Demand();
            return true;
        }
        catch (SecurityException)
        {
            return false;
        }
    }

    public static bool CanWrite(string key)
    {
        return HasAccess(RegistryPermissionAccess.Write, key);
    }

    public static bool CanRead(string key)
    {
        return HasAccess(RegistryPermissionAccess.Read, key);
    }
}

And from there just call either CanRead() or CanWrite() to check for access on a key:

using System;
using Microsoft.Win32;

class Program
{
    static void Main(string[] args)
    {
        string key = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        string value = "MyApp1";

        if (RegistryInfo.CanRead(key))
        {
            Console.WriteLine("Previous value '{0}': '{1}'",
                value,
                Registry.GetValue(key, value, "(null)"));
        }
        else
        {
            Console.WriteLine("No permission to read key: '{0}'", key);
        }

        if (RegistryInfo.CanWrite(key))
        {
            Registry.SetValue(key, "MyApp1", "C:\\WINDOWS\\myexe");
        }
        else
        {
            Console.WriteLine("No permission to write key: '{0}'", key);
        }

        if (RegistryInfo.CanRead(key))
        {
            Console.WriteLine("Updated value '{0}': '{1}'",
                value,
                Registry.GetValue(key, value, "(null)"));
        }
        else
        {
            Console.WriteLine("No permission to read key: '{0}'", key);
        }
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As an alternative to Inno Setup, I'd also recommend WiX. That's what we use at my consulting company in place of the Visual Studio setup project, which has given us trouble in the past, and it's proven quite versatile and powerful (if a little obtuse initially).

Also note that if you're using the Express versions of Visual Studio, the setup and deployment templates are not included out of the box.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

storage
In formal terms, "static" is a storage-class specifier.

That doesn't uniquely define static though. There are other storage class specifiers, and data types in general can be described as partially defining a variable's storage attributes.

Unfortunately, persistence doesn't quite cut it either if we're talking about a language like C++ because the static keyword is overloaded to mean different things. At file scope, static would be better described as defining a variable's visibility. As a static class member, a better description might be to define a variable as shared between objects of the class. At function scope, persistence is an excellent choice of words.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can Coffee Really wipe out sleepiness. I do it a lot but still i become sleepy.

Coffee doesn't make you less sleepy, it's a stimulant that temporarily suppresses the sleepiness. Like all stimulants, there's a crash when it wears off that has you worse off than before. The best way to avoid sleepiness is to get enough sleep.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oh, in that case what's the reason for it in the software forums -- suggest Dani remove it there.

It's basic Markdown. While possible, I don't really see the necessity of restricting the core formatting like that just for the development forums. However, I do agree with Mike that the font could be tweaked...maybe with an underline attribute and a smaller size.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I suppose you could give an user an award for reading it. Or a badge. There was a site once, I thinkit was some pro photo upload site (istockphoto??) that tested its proto-members on the rules/regs. They weren't allowed full status until they passed the test. I failed. Ten times. Sod it.

I'd totally write something like that if I thought it had any chance in hell of not being vetoed by Dani. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That "for" loop (according to what you have said) is the same as a while loop saying:

Close. It's more like this (note that the braces introducing a scope are significant):

{
    int i = 5;

    while (i < 2)
    {
        System.out.println("What?");
        i++;
    }
}

System.out.println("Who?");

Since i is never less than 2, the loop body is never entered, and the only output is "Who?".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

make sure #include <stdlib> and system("PAUSE") in the code to dispplay.

That's only necessary when you're running the program from an IDE that closes the window after main() returns. Not all of them do that, and it's often not worth the subtle yet hideous security risk of invoking the system() function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm digging the name, bootstraptor. Welcome aboard. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As Dani says - it was at the top and very few people clicked on it.

If you want something to remain unread, don't label it "Top Secret" or "Don't Click This". Instead, label it "Rules", or "FAQ", and you'll guarantee that nobody will click the link regardless of its location.

I'd be willing to bet that the majority of clicks for the rules link comes from moderators.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My first approach would be to monitor the last write time for the USBSTOR registry key in a windows service and persist those results in a separate database or file. Really the most difficult part of that would be working around the complete lack of support for time stamps in registry keys. So you'd have to drop down to the Win32 API for that information.

For example:

using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;

class Program
{
    static void Main(string[] args)
    {
        string usbStor = @"SYSTEM\ControlSet001\Enum\USBSTOR";

        using (var keyUsbStor = Registry.LocalMachine.OpenSubKey(usbStor))
        {
            var usbDevices = from className in keyUsbStor.GetSubKeyNames()
                             let keyUsbClass = keyUsbStor.OpenSubKey(className)
                             from instanceName in keyUsbClass.GetSubKeyNames()
                             let keyUsbInstance = new RegistryKeyEx(keyUsbClass.OpenSubKey(instanceName))
                             select new
                             {
                                 UsbName = keyUsbInstance.Key.GetValue("FriendlyName"),
                                 ConnectTime = keyUsbInstance.LastWriteTime
                             };

            foreach (var usbDevice in usbDevices.OrderBy(x => x.ConnectTime))
            {
                Console.WriteLine("({0}) -- '{1}'", usbDevice.ConnectTime, usbDevice.UsbName);
            }
        }
    }
}

/// <summary>
/// Wraps a RegistryKey object and corresponding last write time.
/// </summary>
/// <remarks>
/// .NET doesn't expose the last write time for a registry key 
/// in the RegistryKey class, so P/Invoke is required.
/// </remarks>
public class RegistryKeyEx
{
    #region P/Invoke Declarations
    // This declaration is intended to be used for the last write time only. int is used
    // instead of more convenient types so that dummy values of 0 reduce verbosity.
    [DllImport("advapi32.dll", EntryPoint = "RegQueryInfoKey", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
    extern private static int RegQueryInfoKey(
        SafeRegistryHandle hkey,
        int lpClass,
        int lpcbClass,
        int lpReserved,
        int lpcSubKeys,
        int lpcbMaxSubKeyLen,
        int …
ddanbe commented: Phew man, you know some things! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you do it on paper? Knowing how to solve the problem manually is paramount if you want to tell the computer how to do it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is an obvious answers.

Sometimes the answers are obvious. Not everything has to be complicated. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Thread moved to C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Apply electric shocks to your genitals.

Kinky.