deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No, these are not equivalent at all. If you try to compile and link the second piece of code, you'll get a linker error telling you that a has not been defined.

My bad for being in a hurry. I forgot to include a definition to make the code compile. But the point remains: extern is the default when you don't explicitly state the linkage at file scope.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It looks like you're mixing standard C and Objective-C. Note that this is the C forum, did you mean to post in the Objective-C forum?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An array of pointers is possible beacuse pointers are similiar to variables.

Pointers are variables, and the values they hold are addresses.

*pt[3] is an array of 3 pointers i.e 3 locations are set aside for the storage of the addresses of 3 variables.

In the context of a declaration, yes. *p[3] is also a valid expression that dereferences the 4th element of an array.

Another added advantage is that we can have variable length arrays.

"Variable length" isn't the term you want, since it has connotations that don't apply (such as being able to grow and shrink the size of an array, or define the size at runtime). I think what you meant was a jagged array, where each sub-array can be of a different size. However, this only applies when taking into account that pointers can be used to simulate arrays. An actual 2D array cannot be defined as a jagged array because there's no way to tell the compiler that you want varying sizes for individual elements.

Pointers to arrays are declared as (*ptr)[4]. I don't understand what is the difference between this definition and the one I gave above.

The first is an array that contains pointers. The other is a single pointer that can point to an array type. It might help if you incorporated the concept of pointers with the concept of types. A pointer is a variable that holds an address, nothing more. There are …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strcmp() doesn't return a boolean, it returns a relation:

  • <0 - The first string is lexicographically "smaller".
  • 0 - The two strings are equivalent.
  • >0 The first string is lexicographically "larger".

So when you want to test for equality, it should look like this:

if (strcmp(a, b) == 0) {
    /* Equal */
}
else {
    /* Not equal */
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Line 11 of your program doesn't call the function, and as a result the compiler assumes you want that function's address. You need to include the argument list to call it:

printf("%d %d\n", n, powerof2(n));
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@sepp2k Then why does the code give no error if I remove static and write simply int a; a=5;

Because the default linkage at file scope is extern. This:

int a;

int main(void)
{
    a = 5;
    return 0;
}

Is functionally identical to this:

extern int a;

int main(void)
{
    a = 5;
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I hope they weren't "Americanized". I've seen what they do to perfectly good anime.

It's gotten better over the years, but I was turned off to any kind of modification ("americanizing", or even dubbing) since the travesty of Sailor Moon in the English adaptation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I plan to go to work every weekday, just like the rest of the year. Slightly improved traffic will be a nice change though.

Ketsuekiame commented: Coming up to Easter half term here. I am also looking forward to my journey time reducing by 15 minutes each way ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am receiving such annoying PM from mvmalderen.

I'd suggest ignoring them if they annoy you so much. If you get PMs that are abusing or harrassing, feel free to report them.

This must be either through Post in feedback not through PM.

There's no such requirement. I suspect you're misinterpreting a clause of Keep It Organized: "Do not ask anyone (member or moderator) for help by email or private message". However, note that this clause specifically prohibits asking for help. If someone wants to send you a PM to clarify reasoning for downvotes then that's fine. It's also a good idea for the stated reason of not further derailing a thread by airing dirty laundry.

Is this not violation of rule

It's not a violation of any rule.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Keep in mind that linked-lists are theoretically nice and make for good prorgramming exercises in computer science classes, but they are far from being all that useful in practice.

All these fancy data structures, and the go-to data structure is nearly always an array. That's one of those nasty realities that tend to smack new programmers in the face when they enter the professional world.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Basically, I consider any down-vote without a comment and obvious reason a drive-by.

There's no way to programmatically determine a drive-by according to that definition. I'm still debating with Dani about flood control for votes though. We'll see how that goes down, but our history on that topic is Dani:2, James:0. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think a reasonable compromise is to ignore drive-by voting when it comes to a member's overall score.

What is the definition of a "drive-by" voting? I'm not sure there's any way to deterministically mark votes as drive-by.

but would prevent what happened to (I believe it was) lastmitch who had someone go through and downvote hundreds of posts, thereby driving his post quality into the low 30s.

So basically you're asking for flood control. That doesn't accomplish anything as concerns the topic of this thread, which is figuring out why a post has been downvoted, but I agree thoroughly. In fact, I agree so thoroughly I just committed a patch that implements flood control on votes. We'll see if Dani approves or thinks the trips to the database will be too resource intensive (thus forcing me to get creative).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

even someone downvoted the post in which i have asked for the reason why it is downvoted.check this.

That was me. ;) Hopefully you don't need my reasoning, but I'll be happy to provide it anyway. All you did was copy paste what stultuske write in the post immediately above yours. The pointless repetition wasn't even humorous in this context, it just came off as childish and whiny.

[troll]
I chose not to upvote any of the frivolously downvoted posts in that thread because it would break them as examples of frivolous downvoting. Maybe we should add a feature that anonymously gives reasons why someone didn't vote on a post. ;D
[/troll]

tux4life commented: [troll]Accompanied with a trollvoter to troll that feature :D[/troll] +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if I post an error, someone downvotes it and adds as reason <hypothetical>: no, what you suggest is the use of deprecated methods, ... now that I can understand, appreciate and learn from.

Once again, if the voter were interested in providing a reason, he'd use reputation or reply to your post (or a combination of vote/rep and a reply) and explain it. In this particular example, the best approach would be a reply explaining that you used deprecated methods and elaborating with what the modern methods are.

Allow me to offer an alternative example to your hypothetical downvote. Let's say that someone votes negatively, but offers the helpful comment of 'wrong', or 'blah blah'. Forcing a comment doesn't ensure that the comment will be meaningful. Even with rep you'll see a lot of comments that aren't helpful in discerning why the person in question voted.

Your first way does seem cleaner. It would also allow you to "link" your downvotes at a later date should you wish. I tend to favour this model of development, however, I can't see your code so the cost may outweigh the potential benefit.

Agreed. However, looking at the code, a fundamental redesign wouldn't be justified by what still seems like dubious benefit. The only benefit I'm seeing so far in this thread is if the voter provides a meaningful comment on a downvote, one might recognize the problem, agree with it, and learn from the perceived mistake. There are …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Would it be possible to implement a system that requires a sensibly sized comment to be entered before a down-vote is actioned whilst remaining anonymous?

We own the code and designed the system, so it's most certainly possible. ;) I don't dislike the idea, by the way. In a certain sense, I'm playing devil's advocate here just to make sure that if we choose to make a change, it's been fleshed out from all perspectives.

If you're going to downvote someone, you must have a reason as to why. I don't think it's unreasonable to require someone to enter that reason, even if the commenter remains anonymous.

Your logic is selective. If you're going to vote either way, you must have a reason why, right? So why should negative votes be the only ones requiring a comment, anonymous or not? I've gotten upvotes that were just as baffling as your example downvote, yet it's somehow important that only the downvote be explained?

Because you can anonymously downvote without a reason, you could just find all posts by one person and downvote them. If you had to spend time writing out a reason each time (or even copy/pasta) it makes it less worthwhile. In the case of copy/pasta, it would be easy for you (as a moderator) to see and check a complaint of revenge voting.

All true, though a slew of downvotes from a single person as if they went down the list of …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's be realistic for a moment and consider the human condition. Since you asked to know who downvoted, specifically, and not who voted in general, it's kind of obvious what the implied intention is. You want to know so that you can accost the voter, find out why they were so impudent as to downvote you, and possibly even strongarm them into reversing it. The more noble members will take the reason to heart and try to avoid similar behavior in the future, but the reality is that the vast majority will be offended and not change their ways, even for perfectly valid and reasonable votes.

I don't really feel strongly one way or another about this issue, but I feel it's important to recognize both the reason for wanting a feature as well as the likely negative effects of implementing it. However, in full disclosure, a bulletpoint near the top of my list of things to do is write an admin page for searching vote records. ;)

that potential is already there. chances are you know, or assume to know, who it was and downvote that person.

Unless that person confirms it, you don't know, you only assume to know. Even I don't know without asking Dani to query the production database. With named downvotes, you're sure, and will probably be less hesitant to go on the offensive. Please don't misunderstand that this is the only reason votes are anonymous, it's just the first possible negative effect …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the voter were interested in explaining his or her reasoning, they would leave a comment rather than just vote, or reply to the thread in addition to voting. I'm not sure I see the benefit of showing who down votes, given the potential for revenge voting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

On the endorsements, i noticed that i have several endorsements on C# and Java and i was wondering if they should show up in the "Favorite Places to Post" section?

They show up on the main view of the forum or category where you've been endorsed. So at present you have 5 C# endorsements and that can be seen by hovering over your avatar on the list at the bottom of the C# forum.

Also the count is still off, it shows that i have 18 on the bottom of the web design section even though i have more than that.

It looks correct to me. All forums correctly reflect the count on your profile. Unless you somehow know you've gotten more endorsements than are listed on your profile, I don't see a problem.

This may be irrelevant but i also noticed that i recieved reps from a user who had 7 rep points and my rep points didn't go up even thought i was told it would go up If the user didn't have 0 rep points and didn't give you reps in the community center...

Rep power doesn't correspond directly with rep points. Rep points contribute to your rep power, but there's more to the calculation than that. Our rep power calculation method is actually about 30 lines of conditional math. You can view someone's rep power underneath their rep points, it's split between positive and negative power.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For instance, is toupper() and tolower() supported in C99?

Yes.

Does anyone know where a reliable reference for stuff like this?

What better reference than the standard itself? :D It's the draft standard, but the difference between the final draft and the official standard is really just minor verbiage tweaks. While I wouldn't suggest basing a compiler on the draft, it's more than sufficient for end user programmers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Though if you search through the feedback threads, I posted the complete list of automatic titles (as it was then) not long after we went live with the new system last March. I'm reasonably sure it hasn't changed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it is like when the phone rings,the answering machine should answer the call automaticatically from the system using the modem.

Yes, that's obvious. What's not obvious is whether this is a simulation or you're actually programming for hardware. If this is a simulation then it constitutes homework, and I'll direct you to our rules about proof of effort. If this is an actual answering machine then your first line of attack is learning how to interface with the hardware (ie. reading the documentation).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's usually recommended that people start with Beej's Guide to Network Programming.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

draw() looks like an event handler. What object and event is it attached to? Since it only accepts EventArgs, you don't have access to a Graphics property. So unless your event handler is malformed and should be taking something like a PaintEventArgs, you'll need to grab the Graphics object from the control itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's no use in web.config, that setting is for Windows Forms rather than ASP.NET.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you provide any more details? Or were you actually expecting useful help from that vague description?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In Assembly there's not going to be much insight on linked lists, B trees, arrays, etc.

Um...what?

In fact those don't even exist at the bit level.

They don't exist at any level. Data structures are an abstract concept that get implemented using available language features. You can create a linked list, binary tree, etc... using assembly just as readily as in any full featured programming language.

So if we realize that the closer we get to the architecture the lesser the abstraction gets, and that our [...]

It seems like you quickly got off topic and started ranting about something completely different than the title of this thread suggests. What's your point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why would you want to increase the size?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is there any chance that a set of rules could be implemented to prevent abuse of the endorsement system?

Given that you can only endorse once per account per favorite forum, it's pretty tedious to abuse the system. You could certainly call all of your friends who have an account and ask them to endorse you, but does that really buy you anything?

The metrics are intended to be viewed as a whole, with endorsements added most recently to provide a view on how people see you as a valued poster in your favorite forums.

  • Account Age: Has this member been around long enough for others to get a good taste of their expertise?
  • Post Count: Are subsequent quality metrics statistically significant?
  • Contributions: Does this member ask more questions (starting discussions) or answer more (reply to discussions, post tutorials, post code snippets, etc...).
  • Favorite Places To Post: Does this member have a broad range of skills and/or interests?
  • Activity Points: How does this member spend their time? Ideally you'd want to see a member posting in articles. Note that moderators tend to have relatively high PM counts due to how the moderation system works (you get a PM automatically when we do just about anything).
  • Up Votes & Unique Members who have voted: How many individual posts have been voted positively and are there a lot of unique voters? This suggests that a lot of people appreciate this member's posts. If the number of unique voters is small …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The answer to this is that comments are replaced by preprocessor into white spaces before the macros are even seen!!

That's correct. It's not the macro itself that's wrong, it's how you were using it on the assumption that it would start a comment. For example:

#include <stdio.h>

#define STR_VAL(x) #x
#define STR(x)     STR_VAL(x)

#define comment /##/

int main(void)
{
    printf("'%s'\n", STR(comment));
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

fscanf(filePointer, "%[^\n]", myCharArray)

As an aside, this is no better than gets(). you can fix it by providing a field width though:

char myCharArray[100];
fscanf(filePointer, "%99[^\n]", myCharArray);

This ensures that fscanf() will never write more characters than the array can hold (99 "real" characters, plus a null character at the end). However, it can be problematic if you use something like BUFSIZ for the array size because it's not as simple as just throwing a literal value into the field width. You can kind of cheat it in the case of macros using a stringizing macro:

#include <stdio.h>

#define STR_VAL(x) #x
#define STR(x)     STR_VAL(x)

#define SIZE 10

int main(void)
{
    char line[SIZE + 1];

    printf("Format string: '%s'\n", "%" STR(SIZE) "[^\\n]");

    fputs("Please enter a line: ", stdout);
    fflush(stdout);

    if (scanf("%" STR(SIZE) "[^\n]", line) == 1) {
        printf("'%s'\n", line);
    }

    return 0;
}

But the more general method is generating the format string at runtime with sprintf():

#include <stdio.h>

int main(void)
{
    char fmt[1024];
    char line[10];

    sprintf(fmt, "%%%d[^\\n]", sizeof(line) - 1);
    printf("Format string: '%s'\n", fmt);

    fputs("Please enter a line: ", stdout);
    fflush(stdout);

    if (scanf(fmt, line) == 1) {
        printf("'%s'\n", line);
    }

    return 0;
}

The benefit of this is you can use sizeof or any variable to get the size of the array rather than rely on macro repetition, just like fgets(). But that raises the question of if you're going to all of this trouble to simulate fgets(), why not just use fgets()? …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

you mind i ask where i can put a clrscr command on your codes

How about nowhere? clrscr() is a Turbo Cism, it basically makes your code non-portable for no good reason at all. In fact, you should avoid the entire conio.h library whenever possible.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Accelerated C++ and C++ Primer 5th edition don't have answers!

That's a good thing. Then you won't be tempted to just look at the answer and have to work through the chapter over and over until internalizing all of the information necessary to complete the exercises. You learn more by not having answers readily available. If I recall correctly, Accelerated C++ actually mentions choosing not to provide answers and explains why in chapter 0.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

yeah it would be really easy not to use recursion at all.

It is using recursion, just not 100% recursion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how do i write a program which counts the similarities between two words...

Um, you mean like a Levenshtein distance?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are meant by standards in fact!

Essentially, standards are a complete enough description of the language and library (syntax, semantics, limitations, etc...) to write a compiler. Without standards, each compiler would define its own unique dialect of the language, which would mean you can't take code from one compiler and expect it to compile on another. With standards, as long as your code conforms to the rules laid out by the standard, you can compile your code on any conforming compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My first approach would probably be to check the parent process and kill the program if the parent is a shell, like bash or csh.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It is using little endian notation but I can't understand how the C compiler knows the endianness beforehand.

The compiler is written for a specific platform, and the platform's endianness is well known.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could take the easy way out and use a loop to handle removing the blanks, though I suspect your assignment wants recursion to handle everything:

void compact(char *s)
{
    if (!s[0] || !s[1]) {
        // Fewer than 2 characters left in the string
        return;
    }

    if (isspace(s[0]) && isspace(s[1])) {
        // Shift-overwrite the current whitespace character
        for (int i = 0; s[i]; i++) {
            s[i] = s[i + 1];
        }

        compact(s);
    }
    else {
        compact(s + 1);
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

oh, so technically, most people that give me rep points don't ever have rep points to begin with?

Either that or the rep you're given is in the community center (where rep power doesn't apply).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As the titles says I wanna know what are versions of C++ other than Standard C++ and what are the differents between those version if any!

Every compiler offers extensions to both the language and the library, but you can generally say that the different "standards" of C++ are as follows:

  • ARM Standard: Compilers released earlier than 1998. They may or may not conform to some parts of C++98 due to how long it takes to release a standard document. The de facto standard at the time was defined by The Annotated C++ Reference Manual (called the ARM).
  • ISO C++98: The first official international standard. When a compiler says it conforms to C++, it must at least be C++98.
  • ISO C++03: Minor wording changes and fixes to the 1998 standard in 2003.
  • C++0x: Intermediate support between C++03 and C++11 of C++11 features while they were in development.
  • ISO C++11: The final and most current standard released in 2011.

Second question what is contained in the .exe file I'm using Microsoft compiler "Visual Studio 2010 IDE"?

It contains stuff necessary for the OS to load and run your program such as certain variable definitions, data, instructions for executable code, and library references.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you're expecting methods in the class to work together within the timeout period then you can use one object, but be prepared to reopen it as necessary. The problem is that the timeout defaults to 15 seconds, so it's not like you can open a connection in the constructor of your server object and expect it to remain pristine for life.

But it's also not a great idea to open a new connection every time you want to run a SQL command. A balance is important, but it's hard to say what the balance is for your application.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That would mean that the input should be 1 AND 2 AND 3 in the same time, not?

You're comparing inequality, not equality. So if the input is not 1, not 2, and not 3 then the loop will continue.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your do..while condition is self defeating. Try using && instead of ||.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so void may ignor or b a pointer?

void is a type, just like int is a type. However, void is a very restricted type in that you can't do very much with it.

BUFSIZ what does it do?

BUFSIZ is a macro defined in stdio.h that represents the size of default stream buffer for things like stdin and stdout. It's a convenient value for input buffers in user code as well, and it usually expands to something like 512 or 1024. So given the assumption that BUSIZ is defined like this:

#define BUFSIZ 512

We can then say that char buf[BUFSIZ]; is equivalent to char buf[512];.

same with fflush(stdout)

fflush() forces output streams to write buffered characters to the destination. This can be confusing because the buffering is well hidden, but when you say printf("Enter text: "); there's no guarantee at all that the text show up on your screen immediately because printf() isn't required to flush the buffer. There are only two cases where you can absolutely control whether the buffer is flushed:

  1. When you send '\n' to the stream. If the printf() were changed this printf("Enter text:\n"); then stdout would be flushed automatically, but that would make the output less attractice because then the prompt and input would be on separate lines.

  2. When you call fflush(). Note that fflush() is only defined for output streams. You're almost guaranteed to see things like fflush(stdin), but those are wrong because stdin …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

most of your code we havent tackled yet

Get used to that feeling. If you're not confused 90% of the time, you're not growing as a programmer.

firstly what does void do and when do i use it same with static int??

void does two things:

  1. It represents "nothing". So if you're returning nothing from a function, the return type would be void. If you're accepting no parameters to a function, the parameter list would be void. If you're ignoring a return value and the compiler complains, you can cast it to void. For example:

    (void)getchar(); // Read a character and ignore it
    
  2. In the context of a pointer, void* is C's concept of a generic pointer that can point to any object.

As concerns static int, those two keywords do different things. The return type of the function is int, and the function itself is qualified as static to give it visibility only to the file it's defined in. If you don't qualify functions as static, they're extern by default, which means that any other file can call the function. For the most part you can simply not worry about that behavior until later. I made those two functions static as a matter of good style because they're only intended to be used in a single file.

so when i try use isostream it wont take it

iostream is C++, not C.

sorry if i got alot alot of …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the thing is can you explain to me those codes please i really wanna learn...

I'll be happy to explain anything you want, but there's too much to explain everything possible from top to bottom. Please specify areas that are confusing you and mention why you're confused. That gives me a place to focus on in my explanations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Just to double check, that's what you meant by your example right?

No, I used _registers and _numRegisters as names for data members in the class:

class Screen {
    Register* _registers;
    int _numRegisters;
public:
    Screen(Register* registers, int numRegisters);
};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I still haven't got my head around pointers which I think is the problem.

Every object reference you used in Java...was a pointer. The only differences are Java references don't use explicit dereferencing operators, and Java references are restricted in terms of things like pointer arithmetic. That may help you conceptually.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's hard to say without knowing the purpose of the Screen class. What is a "screen" in this context? The call to the constructor suggests one of two things:

  1. The Screen object will take ownership of a pointer to the registers created by the caller:

     Screen::Screen(Register* registers, int numRegisters)
         : _registers(registers), _numRegisters(numRegisters)
     { }
    
  2. The Screen object will make a copy of the given "array" (many possible variations):

     Screen::Screen(Register* registers, int numRegisters)
     {
         _registers = new Register[numRegisters];
    
         for (int i = 0; i < numRegisters; i++) {
             _registers[i] = registers[i];
         }
     }
    
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what's the problem? The connection string will contain the name of the machine hosting the database, and if all machines are on the same network, it's no different than connecting to a local database.