Skip to main content

All Questions

60votes
2answers
93kviews

What is the difference between function() and function(void)?

I have heard that it is a good practice to write functions that do not receive anything as a parameter like this: int func(void); But I hear that the right way to express that is like this: int func(...
Grizzly's user avatar
56votes
11answers
24kviews

What are the best practices regarding unsigned ints?

I use unsigned ints everywhere, and I'm not sure if I should. This can be from database primary key id columns to counters, etc. If a number should never be negative, then I will always used an ...
wting's user avatar
  • 1,044
56votes
6answers
287kviews

Is initializing a char[] with a string literal bad practice?

I was reading a thread titled "strlen vs sizeof" on CodeGuru, and one of the replies states that "it's anyways [sic] bad practice to initialie [sic] a char array with a string literal." Is this true,...
Cole Tobin's user avatar
32votes
11answers
20kviews

typedefs and #defines

We all have definitely used typedefs and #defines one time or the other. Today while working with them, I started pondering on a thing. Consider the below 2 situations to use int data type with ...
c0da's user avatar
  • 1,526
27votes
1answer
20kviews

Where did "exit(-1)" come from?

I see in a lot of legacy software and bad tutorials on the Internet that recommend using exit(-1), return -1 or similar to represent "abnormal termination". The problem is, in POSIX at least, -1 has ...
user222973's user avatar
22votes
2answers
4kviews

Has variable width types been replaced by fixed types in modern C?

I came across an interesting point today in a review over on Code Review. @Veedrac recommened in this answer that variable size types (e.g. int and long) be replaced with fixed size types like ...
jacwah's user avatar
16votes
10answers
9kviews

Preferring Python over C for Algorithmic Programming

I've been studying a bit of algorithms and have been looking at sites like SPOJ.pl TopCoder etc. I've seen that programmers prefer C or C++ usually for most algorithmic programming contests. Now I'...
ffledgling's user avatar
16votes
2answers
4kviews

Best overview to modern C++ paradigms? [closed]

I used to write C++ extensively between 8 and 10 years ago. I have since moved on to C# for professional reasons. However, from time to time I see statements like "If you're still manually ...
GWLlosa's user avatar
  • 1,159
14votes
8answers
34kviews

Are C strings always null terminated, or does it depend on the platform?

Right now I am working with embedded systems and figuring out ways to implement strings on a microprocessor with no operating system. So far what I am doing is just using the idea of having NULL ...
Snoop's user avatar
  • 2,748
12votes
3answers
3kviews

Is it bad to refer to access array elements via pointer arithmetic instead of the [] operator?

I've just started learning to program in C, and to improve my understanding of pointers and arrays, I tried to refer to the elements of an array without creating any pointer at all: for(k1 = 0; k1 &...
Niko Gambt's user avatar
10votes
6answers
4kviews

Why are people coding "C-style C++"?

In discussions about whether to cast the result of malloc or not when coding C, one common argument is that if you cast the result then you can compile your C code with a C++ compiler. Why would one ...
klutt's user avatar
  • 1,438
7votes
8answers
2kviews

Why has the rate of programming language popularization slowed down in recent decades? [closed]

If I understand correctly, there was a huge birth of programming languages during the early decades of computing, but then things have stabilized. Basically, why are many universities and industries ...
Dark Templar's user avatar
5votes
8answers
1kviews

Grading an algorithm: Readability vs. Compactness [closed]

Consider the following exam / interview question: Implement the strcpy() function in C: void strcpy(char *destination, char *source); The strcpy function copies the C string pointed by source into ...
amiregelz's user avatar
5votes
6answers
5kviews

Why is C++ backward compatibility important / necessary? [closed]

As far as I understand it is a wide-spread opinion within the C++ community that certain features of C++ (including some features inherited directly from C), while still usable in themselves, do not ...
Giorgio's user avatar
  • 19.8k
5votes
1answer
474views

Scoping recommendations while developing in C

While developing a library using C, what are your recommendations about variable and function scoping? In C++, OOP and namespaces made the whole thing a lot easier. But how to do that with plain C? ...
Gulshan's user avatar
  • 9,532

153050per page
close