C is a general-purpose computer programming language used for operating systems, games and other high performance work.

learn more… | top users | synonyms

6
votes
6answers
10k views

Is it possible to write an operating system in C? [closed]

A while back I saw a comment on a Stack Overflow question that surprised me: No one can write an operating system in C. It is not possible. What one can do is write an operating system in a ...
17
votes
7answers
1k views

How to avoid the pitfalls of static analysis

I'm working at a company that would score 11 on Joel Test - at least on paper. In practice, however, nothing works quite as well as expected, and the project has been on DEFCON 1 for half a year. ...
-1
votes
1answer
81 views

What is the hash value of each member of the group? Before modding?

This isn't an actual code related question but it relates to C. We are given: Amy's club has grown and now includes the following members: Abel, Abigail, Abraham, Ada, Adam, Adrian, Adrienne, ...
1
vote
2answers
54 views

One C codebase as an standalone application as well as Fast-CGI and Apache module

I'm familiar with C, but haven't written any medium or large application in it. I have a requirement to built an application that can be run as a standalone console application as well as Fast-CGI and ...
-2
votes
1answer
603 views

Bresenham Vs Midpoint Circle drawing algorithm

Can somebody explain the difference between Bresenham and Midpoint Circle drawing algorithms? All I am able to understand is that in both algorithms we compute coordinates of an octant instead of ...
5
votes
1answer
125 views

Strategies to increasing the maintainability of assertions in code [closed]

Background I am writing a compiler for a custom language for a school project and it is going really well for me. If I where to start all over from scratch I would have done many software ...
3
votes
1answer
214 views

Are include guards necessary if headers only contain declarations?

Consider the following assumptions about C programming (some of which go too far, I confess): Putting any variable definitions in a header file is incorrect, because each translation unit creates ...
-1
votes
1answer
163 views

Why '-5<(unsigned)5' is false? [duplicate]

In c programming why I am getting 0 zero for this? Why -5<(unsigned)5 is false? main(){ printf("%d",-5<(unsigned)5); getch(); }
-2
votes
1answer
150 views

How did the gets function ever make into the standard? [closed]

We all know the dangers of gets. It is also on the way out in C11. That makes me wonder: how did it ever get into the standard to begin with? Weren't the problems with it obvious at the time of ...
2
votes
3answers
5k views

Why does an unsigned int compared with a signed character turn out with an unexpected result? [closed]

Why does the following code output y>x when clearly 1>-1? unsigned x=1; signed char y=-1; if(x>y){ printf("x>y"); } else { printf("y>x"); } Please explain this result.
5
votes
6answers
126 views

Benefit of non-volatile access to volatile objects being undefined?

This is a question about ISO C, which contains this sentence: If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with ...
3
votes
4answers
997 views

Is a makefile really needed

I have been programming in c/c++ for a while now, and I have never once used a makefile. I know that it is supposed to be useful when you are dealing with a large project, but I have always been able ...
0
votes
2answers
385 views

Write C line by line

Is there any conceptual limitation that would make impossible to create a C program line by line as in 'Mathematica notebooks'[1]? [1] One key aspect of Mathematica is that you can create your code ...
14
votes
4answers
2k views

Why do some programmers categorize C, Python, C++ differently? - regarding level

I am taking an introductory course on python and the instructor says that python is a high level language and C and C++ are low level languages. It's just confusing. I thought that C, C++, Python, ...
0
votes
1answer
214 views

Is C programming language low level or high level? [duplicate]

What do you think, is C programming language low or high level? There are some information, in one is said that C is low level, and another C is high level? When I read book of Dennis Ritchie and ...
1
vote
2answers
888 views

Searching algorithm used in switch statement

What is the searching algorithm used in switch statement in C language? If the cases are not in order still it searches proper case which means it is not a binary search algorithm, can anybody ...
24
votes
4answers
884 views

C++ Linkage Languages other than C?

The C++ language allows intermixing of both C++ and C in one source file. For example, extern "C" { struct bar { /* ... */ } } Does C++ or has it ever supported any other "linkage languages" ...
52
votes
7answers
4k views

Should one check for every little error in C? [duplicate]

As a good programmer one should write robust codes that will handle every single outcome of his program. However, almost all functions from the C library will return 0 or -1 or NULL when there's an ...
11
votes
7answers
10k views

How to get started in opensource projects and programs [duplicate]

I am interested in starting to learn how to contribute to open source projects and Linux in general. I am a first year B.Sc. Computer Science student this year and we use c++ as our main programming ...
0
votes
1answer
153 views

C automatic variables [closed]

I'm designing 2 functions, I'm trying to be sure I doing correctly. The idea is that in the first function , a struct pointer is created and passed to a function that might or might not fill the said ...
0
votes
1answer
52 views

Overwriting a C system after exec? [closed]

So I used wrap to override the malloc call in my program, I didn't think that if I exec'd another it would work, and it didn't. I figure this is because it wasn't linked with my program. How could I ...
2
votes
1answer
182 views

Memory/cache performance in working with arrays in C

I've been toying with some array examples in C. I want to understand more about memory concepts, alignment, and cache. Especially on large arrays on heap. Sometimes I work on large images (extremely ...
55
votes
5answers
15k views

Why are there no package management systems for C and C++? [closed]

There are some programming languages for which exist a package management system: CTAN for TeX CPAN for Perl Pip & Eggs for Python Maven for Java cabal for Haskell Gems for Ruby npm for NodeJS ...
2
votes
3answers
335 views

Why do most language's definition of substring allow substring(“abc”, 3) => “”

I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely ...
44
votes
16answers
10k views

Languages on a resume: Is it better to put “C/C++” or “C, C++”? [closed]

I'm graduating in a couple of weeks, and my resume (as expected) lists the languages that I've had experience with. Previously I've put "C/C++", however back then I didn't have that much experience ...
0
votes
0answers
37 views

Best way to update driver data from userspace

I have a userspace application which interacts with a kernel-space driver in a Linux environment. The driver, in this case, is an LED driver. In typical *nix fashion, the driver exposes a file in ...
0
votes
3answers
97 views

Proper way to interpret this dereference operation?

I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct: typedef struct { char *data; size_t start, end; } ...
2
votes
1answer
111 views

Questions about compiler/interpreter design [closed]

I am implementing a programming language, for fun, in C. I have most of the parsing code done and also the AST ready. I once did write a runtime for this language some time ago, but I had some trouble ...
3
votes
4answers
1k views

What's the best/most efficent way to create a semi-intelligent AI for a tic tac toe game?

basically I am attempting to make a a efficient/smallish C game of Tic-Tac-Toe. I have implemented everything other then the AI for the computer so far. my squares are basically structs in an array ...
2
votes
4answers
397 views

When was block scope for variables introduced to C, and why is it still frowned upon?

In light of the recent OBJ_obj2txt vulnerability in LibreSSL (which was found during the OpenSMTPD audit, and does not affect OpenSSL), it came to my attention that the memory leak issue likely ...
81
votes
5answers
98k views

How to write a very basic compiler

Advanced compilers like gcc compile codes into machine readable files according to the language in which the code has been written (e.g. C, C++, etc). In fact, they interpret the meaning of each codes ...
133
votes
11answers
20k views

Should I stop using the term C/C++?

I understand C and C++ are different languages but when I was learning C++ I was always told that C is a subset of C++ or C++ is C with classes. And that was quite true until the appearance of C++x0, ...
31
votes
10answers
17k views

Why are pointers not recommended when coding with C++?

I read from somewhere that when using C++ it is recommended not to use pointers. Why is pointers such a bad idea when you are using C++. For C programmers that are used to using pointers, what is the ...
35
votes
7answers
23k views

Is it better to document functions in the header file or the source file?

In languages that distinguish between a "source" and "header" file (mainly C and C++), is it better to document functions in the header file: (pilfered from CCAN) /** * time_now - return the ...
5
votes
1answer
148 views

How can I best test a multithreaded C producer-consumer program? [closed]

How does one best write tests for a multi-threaded producer-consumer C program? I know GDB can be used to debug threads, but I believe GDB also stops the thread currently being debugged while other ...
4
votes
1answer
489 views

Transpose a matrix without a buffering one

How is it possible to transpose a MxN matrix without using a "buffering" matrix? In the latter case it's easy and quite the "classic" approach... Given a matrix[M][N], I would like to put it into a ...
3
votes
2answers
984 views

How does printf write to stdout? [closed]

I've been looking for an answer to this for a couple days, and all of the results I've come up with are about how printf accepts an arbitrary number of arguments. How does printf write to stdout? ...
5
votes
2answers
764 views

Should I always return an error code from C functions?

I have the following code in many places in a large application: if (datastruct.data_ok && cur_time > datastruct.start_time && cur_time < datastruct.end_time) { ...
20
votes
8answers
1k views

Is directly using Make considered obsolete? [closed]

So I have been coming across many comments/posts/etc regarding creating makefiles directly, and how it is a silly thing to do in 2015. I am aware of tools such as CMake, and I actually use CMake quite ...
0
votes
0answers
297 views

Writing Z80 table based assembler/disassembler

I have a long-term project: DIY computer with various processors. One of my wishes not only make hardware, but software too. So I started from assembler/disassembler for Linux, though there is a lot ...
2
votes
1answer
156 views

Using own ArrayList in general purpose C libraries, but allowing a different implementation

I've written a couple of libraries since beginning to use C again last year. One thing that still needs addressing in both of these is the correct use of array-based lists - hereafter, ArrayLists. At ...
0
votes
0answers
535 views

Best way to signal all child processes to terminate using C

I have been assigned the task of designing a simple web server using C in my UNIX & C class. The webserver listens and forks when a successful connection is made so that multiple clients may be ...
1
vote
2answers
118 views

Multi-pattern matching

I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you ...
3
votes
0answers
149 views

Is it okay to write C code that must be compiled with -fno-strict-aliasing? [closed]

Some major C projects violate the strict aliasing rules in the C standard and must be compiled with -fno-strict-aliasing. These include Python, OCaml and the Linux kernel. Obviously this is not ...
-3
votes
1answer
159 views

grouping variables into a system in C? [closed]

Within C, say I have a number of variables, floats, integers etc, is there a way that I can group them all into one object, lets call it a system, and then create N copies of such an object. Further, ...
2
votes
2answers
2k views

Finding header files

A C or C++ compiler looks for header files using a strict set of rules: relative to the directory of the including file (if "" was used), then along the specified and default include paths, fail if ...
3
votes
5answers
2k views

API design pitfalls in C [closed]

What are some flaws that drive you nuts in C APIs (including standard libraries, third party libraries, and headers inside of a project) ? The goal is to identify API design pitfalls in C, so people ...
13
votes
2answers
911 views

How important it is to fix memory leaks?

I found by Valgring that some GTK+ programs leaks memory. How important it is to fix those leaks? I mean, often those programs works very well but on the other hand, one can never be sure if one wants ...
-3
votes
2answers
241 views

How should I proceed to make a program that, when given three sides of the triangle in an array, will determine if they can make a valid triangle? [closed]

Given three sides of a triangle. I have to determine by writing a program using C language whether I can make a valid triangle or not using these three sides of the triangle. So how should I proceed ? ...
3
votes
4answers
169 views

Source control workflow for managing a software platform

I'm in charge of a software platform, written in C, that is used to provide a variety of projects to clients. I am trying to improve the workflow for people using this platform, and looking at ...