Hot answers tagged

9

The algorithm here is: Take the value in the middle of the array, and move it to the front (by swapping). This value is the pivot. Loop through the rest of the array. Each time you see a value less than the pivot, swap it to closer to the front of the array. Specifically we have an index (named last) that keeps track of where the last lesser value was ...


8

To my understanding, standards are mainly for code portability between compilers No, a programming language is a specification (written in some report in English with some formalizations), and that specification is (often) the standard. Some implementations (notably GCC compilers) accept (and document) useful extensions to the standard (such as statement-...


6

Your question is sort of like saying assembly is difficult to work with, so computers should use higher level languages instead. The ANSI format is the right level of abstraction for working with terminal hardware. You have to do the state tracking somewhere, and it's best to not do it in hardware that needs to be as cheap as possible. Even in modern ...


5

In the case of gcc, you can tell the compiler what C standard to use via the --std option. Running man gcc will explain this, and will list all of the standards that are supported. Note that there are lots of variations including some "standards" that are GCC specific extensions / variations to the official standards. If you want to understand why certain ...


4

You can do several things. On an unmodified 32-bit application in Windows you may be able to use DrMemory. (I assume you already configured your compiler to issue all the warnings it can. Never understimate the potential troubles hiding behind a "warning"). You might also port your program to Linux (on a VMware virtual machine, maybe) and use Valgrind. ...


4

If you were not consciously trying to follow the ANSI standard when writing the code, then most likely your code will not conform to any of the ANSI C standards. The reason for this is because there are no C compilers that by default enforce an ANSI C standard, but they all accept their own dialect of C. To add to that, if your program tries to do user-...


4

There is a simple reason. When you are typing you can only input a character at a time. Something that is processing typed text has to deal with what in effect is invalid markup, half a json blob or half an xml document. You can't display "error" until the typing has finished and then display the result. You have to have a format where partial documents ...


3

This particular warning is there for a serious reason: That kind of code opens you up to nasty bugs. If you pass a char* to a function that expects a const char*, that's fine. It just means that the compiler won't allow that function to modify the chars pointed to, even though they may be really modifiable and the compiler would have allowed the calling ...


2

First things first: The original K&R was written in 1978. Expecting that a book written in 1978 is authoritative now is a bad expectation. The C language was an offshoot of B, which in turn was an offshoot of BCPL. In B, the auto keyword was essentially the opposite of the extrn keyword. That is perhaps the best way to think of the modern C extern ...


2

If you have values being changed and you didn't intentionally write code to change them, then in all likelihood, you are writing to an array and overwriting the buffer. This can do all sorts of things. Usually you will see functions getting called that you didn't intend to be called or not getting called etc... However, it can also corrupt your data. I would ...


1

I think the lack of a standard for C++ is a problem in today's world of de-coupled, modular programming. However, we have to define what we want from such a standard. No-one in their right mind wants to define the implementation or platform for a binary. So you can't take a x86 Windows dll and start using it on a x86_64 Linux platform. That would be a bit ...


Only top voted, non community-wiki answers of a minimum length are eligible