Skip to main content
The 2024 Developer Survey results are live! See the results
100 votes

Why are bit masks called "masks" and what purpose do they serve?

A mask (of the facial variety) is something that covers up some parts of your face and lets other parts show through. The terminology is used by analogy in computing: a bitmask covers up (filters out)...
Mason Wheeler's user avatar
68 votes

Why do many functions that return structures in C, actually return pointers to structures?

There are several practical reasons why functions like fopen return pointers to instead of instances of struct types: You want to hide the representation of the struct type from the user; You're ...
John Bode's user avatar
  • 10.9k
55 votes

Why are bit masks called "masks" and what purpose do they serve?

A bit mask is used to mask some bits of a bit field while exposing others: initial value: 011011001 bit mask.....: 111110000 result value.: 011010000 This has been used before computing in ...
mouviciel's user avatar
  • 15.5k
40 votes

Why do many functions that return structures in C, actually return pointers to structures?

There are two ways of "returning a structure." You can return a copy of the data, or you can return a reference (pointer) to it. It's generally preferred to return (and pass around in general) a ...
Mason Wheeler's user avatar
39 votes

Why are bit masks called "masks" and what purpose do they serve?

Bitmasks are terribly old. I haven't been able to find a reference to the first one, but they were certainly popular by the advent of 8-bit processors, and likely were also used in 4-bit processors. ...
Cort Ammon's user avatar
  • 11.6k
34 votes
Accepted

How to comprehend abstraction in code?

Programming concretely is the impulse to pull details towards you so you can nail them all down in one place. We all start this way and it's hard to let go. Programming abstractly is most definitely &...
candied_orange's user avatar
28 votes
Accepted

Why use a higher level language?

"Besides the fact that a higher level language is easier to code in and therefore less error prone" I really think this is a good enough reason all by itself. If you have no compelling reason to work ...
sara's user avatar
  • 2,559
19 votes
Accepted

Why do compilers typically only generate executables for the platform they are installed on?

what makes it difficult for say the visual C++ compiler on windows to generate a linux binary executable file? Other than an unwillingness to do that on Microsoft's part, absolutely nothing. The ...
Blrfl's user avatar
  • 20.4k
14 votes

How can arithmetic, like a bit shift, avoid branching?

This kind of microoptimization is usually avoided because it hurts code readability – and microoptimizations is the job of the compiler. But sometimes these techniques can be legitimately useful. ...
amon's user avatar
  • 135k
13 votes

What principles are learned from C that can't be learned in higher level languages?

I know C is a good language to learn the principles behind programming. I disagree. C is absent too many features to learn principles behind programming. C's features for creating abstractions are ...
Erik Eidt's user avatar
  • 34.2k
13 votes

Why do many functions that return structures in C, actually return pointers to structures?

In addition to other answers, sometimes returning a small struct by value is worthwhile. For example, one could return a pair of one data, and some error (or success) code related to it. To take an ...
Basile Starynkevitch's user avatar
13 votes

How to comprehend abstraction in code?

At the bottom, there are some updates to how this fared for me every quarter of the year or so, I think they're valuable. Good naming. Or, if it's someone else's code, trying to attribute good names /...
coolpasta's user avatar
  • 641
11 votes

Why do many programming languages and applications use integer instead of floating point to represent time?

The core idea behind floating point numbers is that you have some number of bits for the mantissa, and then some number of bits to tell where the decimal point is, and of course a bit for the sign. ...
Theraot's user avatar
  • 9,171
9 votes

How are mixed, sizeless lists implemented in higher level languages?

I guess the kind of "lists" you had in mind are not the "linked lists" mentioned by Robert Harvey, but the kind of arrays which are called list in Python, List or ArrayList in C#, ArrayList in Java, ...
Doc Brown's user avatar
  • 210k
9 votes

What is the absolute minimum set of instructions required to build a Turing complete processor

single instruction CPU implementations This answer will focus on interesting implementations of single instruction set CPUs, compilers and assemblers. movfuscator https://github.com/xoreaxeaxeax/...
Ciro Santilli OurBigBook.com's user avatar
9 votes
Accepted

What principles are learned from C that can't be learned in higher level languages?

There are no principles, in the general abstract sense of computer science, that are present in C that are not also present in higher-level languages. All of computer science boils down to algorithms, ...
greyfade's user avatar
  • 11.1k
9 votes

Why are bit masks called "masks" and what purpose do they serve?

A bit mask is similar to screen printing. You select some certain bit position to be taken over into the result: source value = 42 -> 00101010b mask = 51 -> 00110011b result 42&51 = ...
Timothy Truckle's user avatar
8 votes

Why do compilers typically only generate executables for the platform they are installed on?

Yes, if you have all of the info about your target platform then it should not matter what platform you're actually running on. There's two problems that tend to crop up: People don't focus on it ...
Telastyn's user avatar
  • 109k
8 votes

What principles are learned from C that can't be learned in higher level languages?

C and the (Abstract) Machine Most programming languages are described in terms of abstract machines. Then, they are implemented using sets of tools like compilers, linkers, assemblers, interpreters, ...
Theodoros Chatzigiannakis's user avatar
7 votes

How are mixed, sizeless lists implemented in higher level languages?

The closest thing I managed to write was a class in C++ which allocated a certain amount of memory and, when its size was filled, allocated a longer block of memory, copied the elements in that block ...
Eric Lippert's user avatar
  • 46.3k
6 votes

Is OpenGL just badly designed?

It's extremely popular, dominates on mobile devices, is in active development, and supported on all kinds of GPUs. Why? Well... what's your alternative? Ignoring Vulkan, if you want to write a cross-...
Nicol Bolas's user avatar
6 votes

Why do many functions that return structures in C, actually return pointers to structures?

You’re on the right track Both the reasons you mentioned are valid: One of the reasons I thought that is would be an advantage to return a pointer to a structure is to be able to tell more easily ...
Ryan's user avatar
  • 613
6 votes

Why do many functions that return structures in C, actually return pointers to structures?

Something like a FILE* isn't really a pointer to a structure as far as client code is concerned, but is instead a form of opaque identifier associated with some other entity like a file. When a ...
supercat's user avatar
  • 8,593
6 votes

How can arithmetic, like a bit shift, avoid branching?

But if it returns 0 or -1, wouldn't you still need a branch to check which one it is and execute the according instructions? Not necessarily. As written, the explanation leaves out what to do with ...
Blrfl's user avatar
  • 20.4k
6 votes
Accepted

Is C usually a last resort?

I always find myself wishing I had something like Python's flexible data structures. In fact, I usually end up creating a poor approximation of them. If you're missing data structures, there are ...
Michael Borgwardt's user avatar
5 votes

What principles are learned from C that can't be learned in higher level languages?

The reason why C is good for learning is not that it teaches any principles. It teaches you, how things work. C can be compared with one of those good old cars from the 70s or 80s, which were just ...
cmaster - reinstate monica's user avatar
5 votes

What is the absolute minimum set of instructions required to build a Turing complete processor

What is the absolute minimum set of instructions required to build a Turing complete processor? Jörg W Mittag said, "one," but how about zero? Why do you assume that a "processor" has to have "...
Solomon Slow's user avatar
  • 1,223
5 votes

Why do many programming languages and applications use integer instead of floating point to represent time?

Time is an infinite sort of thing. You can go indefinitely into the past, eventually hit the big bang. And maybe you could stop there, but nothing is stopping you. Likewise you can go indefinitely ...
Telastyn's user avatar
  • 109k

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