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

learn more… | top users | synonyms

1
vote
2answers
57 views

What's the difference between writing to the memory address of a declared int and writing directly to an int*?

I'm writing a program in which I fscanf a file and write to the same memory address repeatedly. I tried the following: FILE *f = fopen(fname, "r"); int* num; while(fscanf(f, "%d,", num) != EOF) { ...
-2
votes
0answers
32 views

Difference Between `int static array[]` and `int array[]`?

I was to program a code for which i have to make a array to store more than million elements . But when i did it , it cannot store more than 120 thousand element so i read somewhere that if i instead ...
2
votes
2answers
87 views

C header file order

I see that in many projects and examples that local includes are listed before external libs and before header files for built in compiler functionality. Is there any advantage here that I am missing?...
0
votes
1answer
71 views

Are there system calls like posix in assembly level using int number for windows

I want to write assembly program using windows syscall Interrupt number , so in order to use system call in assembly level using int of sys call, In windows are there kernel calls like posix ...
-3
votes
0answers
51 views

Write pci access in kernel c? [closed]

Does anyone know how to access the pci and pci express cards in c for an operating system? I don't know how to access the pci cards, but does someone know what I have to do. I want to have an array of ...
0
votes
2answers
75 views

Building a personal C/Python library to replace Matlab [closed]

I am considering to switch from Matlab to Python/C++ for research work. The objective is to create an environment similar to Matlab for rapid prototyping. Python is slow even with numpy and schipy. ...
83
votes
7answers
21k views

Why declare a variable in one line, and assign to it in the next?

I often see in C and C++ code the following convention: some_type val; val = something; some_type *ptr = NULL; ptr = &something_else; instead of some_type val = something; some_type *ptr = &...
2
votes
5answers
208 views

Pointers Or Not

This is a academic question, but I think only professional programmers are the people who can answer this. Is it true that whatever we can do with pointers, we can do without them as well? This ...
-3
votes
0answers
37 views

Sample embedded projects with unit tests written [closed]

I have a question related to the following post: best practice when unit testing for embedded development I am looking for some sample projects (may be on github) that have unit tests enabled. See ...
2
votes
6answers
335 views

“Write an Assembler in C.” Why writing a machine code translator for a low level language in a higher level language?

My Microprocessor class instructor gave us an assignment and said: "Write an Assembler in C." - My beloved Professor So it seemed a little bit illogical to me. If I'm not wrong Assembly ...
4
votes
6answers
2k views

Is it best to minimize using pointers in C?

I think most people would agree that pointers are a major source of bugs in C programs (if not the greatest source of bugs). Other languages drop pointers entirely for this reason. When working in C, ...
0
votes
1answer
81 views

Programming Pearls 1.6.1

I just started Programming Pearls and have already gotten bent out of shape over the first question in Column 1. The problem is to sort a file with up to 10 million 7 digit elements without memory ...
0
votes
1answer
115 views

Getting an array index (0,1,2,..8) from bit masking value (1,2,4,8..256) without using log2(n). Maybe a design issue

I'm working on a component where I put in data and I get different data as a result. The input is always the same (3 Objects). From these 3 Objects up to 9 other Objects can be calculated. One ...
1
vote
1answer
41 views

SPI vs SCI on TI processor

I have a Texas Instruments development board: LAUNCHXL-F28027. I'm confused on the difference between SPI (Serial Peripheral Interface) and SCI (Serial Communications Interface). What are their ...
-1
votes
0answers
77 views

Why does C handle negative modulo values non-standardly [duplicate]

In math the standard for modulo is the remainder of the division; wether the object is positive, negative, or zero. so (-1)%4 would be "3" But in C (and a few other programming languages), (-1)%4 ...
30
votes
13answers
2k views

Help in understanding computer science, programming and abstraction [duplicate]

Until now, I always believed that you should learn programming languages that make you do low-level stuff (e.g. C) to understand what's really happening under the hood and how the computer really ...
1
vote
1answer
130 views

Is there any technical reason to typedef void? [closed]

No opinions, please. Is there any technical reason to typedef void? My current company and my last both have typedef void XYZ_void; where XYZ is the project name. I can understand a typedef for ...
1
vote
1answer
106 views

What does “All examples have been tested directly from the text, which is in machine-readable form” mean?

I am reading the classic book on C - The C Programming Language Book by Brian Kernighan and Dennis Ritchie. The preface of the book says All examples have been tested directly from the text, which ...
2
votes
4answers
204 views

Is C is a portable language for new architecture or it is specific for ISA?

How C language is portable to any instruction set (I mean for new architecture). Do we have to write again C compiler for new architecture?
0
votes
1answer
38 views

DNS-SD implementation

I am trying to implement DNS-SD, and I understand how it works, but don't really understand the purpose, so I have a few questions about it. Let us assume that we have two devices on local network, ...
36
votes
12answers
9k views

Is this a decent use-case for goto in C?

I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the ...
9
votes
5answers
436 views

Is there a way to use gcc as a library?

Anyone knows a solution that works something like this: #include <stdio.h> #include <gcc.h> /* This .h is what I'm looking for. */ int main (void) { /* variables declaration (...) */ ...
1
vote
3answers
246 views

Can you pass a label as an argument, and have the function return to it?

So I would like to be able to call a function like this: void func(1, 2, 3, (void*)label) // can return normal or to the labels //some code label: //different code Is it possible, and is it bad ...
-1
votes
2answers
161 views

Is main() function better on top of all other functions? [closed]

My college professor told me that main functions should be defined on top of other function definitions. We should use a forward declaration in order to accomplish this (we use C at that time). So yes,...
2
votes
4answers
294 views

Are static global variables as bad as global variables? How to avoid using them?

In general, I know that global variables are bad and should be avoided. Are static global variables equally bad? In all my projects, I have heavily relied on static global variables. From design ...
48
votes
8answers
14k views

What happens to garbage in C++?

Java has an automatic GC that once in a while Stops The World, but takes care of garbage on a heap. Now C/C++ applications don't have these STW freezes, their memory usage doesn't grow infinitely ...
2
votes
1answer
93 views

Explicitly mark unexported functions in a DLL?

When writing an unmanaged Win32 DLL that exports functions, it's not uncommon to have some functions, variables and/or classes that aren't meant to be exported and are only for internal use within the ...
26
votes
5answers
50k views

What are the fundamental differences between C and C++? [closed]

Many tend to write "C/C++", as if they were the same thing. Although they share many similarities, they are clearly not the same. But what are really the fundamental differences between C and C++? Is ...
-1
votes
1answer
71 views

How to send a http request through a program developed in C? [closed]

As you read in the title, for example, i wanna login to my account in StackOverflow by sending the E-mail and password through a program developed in c language, so all what i have to do is to enter ...
5
votes
1answer
94 views

Do I need to declare a delay timer variable as volatile even if I access it from another module

This is a question more about using volatile to prevent optimization than about caching write/read of a variable. Particularly timer delay variables since I don't want to declare everything volatile ...
1
vote
1answer
72 views

Using GPLed headers in LGPLed library

For a specific device there exists a Linux kernel module. This module only initialized the device and provides control mechanisms to user land via ioctls and mmap. To use this the device properly one ...
2
votes
0answers
28 views

Zeromq bidirectional asynchronous transmission?

I have a system which consists of two applications. Currently, two applications communicate using multiple zeromq publish/subscribe sockets generated for each specific type of transmission. Sockets ...
6
votes
4answers
8k views

What is the difference between a pointer pointing to 0x0 location and a pointer set to NULL?

Is a pointer pointing to 0x0000 the same as a pointer set to NULL? If NULL value is defined in the C language, then what location does it physically translate to? Is it the same as 0x0000. Where can I ...
0
votes
3answers
312 views

In C, why is NULL and 0 triggering an if statement

I have a function that is called by myStruct *structName = myFunction(0); The function looks like myStruct *myfunction(int x) { if ( x == NULL) { return NULL; } /*rest of ...
4
votes
9answers
2k views

The definition of C-based language

What is the definition of C-based language? Is C# considered to be C-based? Is Java considered to be C-based? Furthermore, what does it mean for a language to be based on another language anyway?
1
vote
3answers
153 views

Writing a #define for a common statement

Often when I program in C I write the expression for (int i = 0; i < j; i++). I never wrote a macro or a define expression, but could I write a #define to simplify the above expression so that do ...
0
votes
0answers
53 views

Converting a 1D character array to a 2D array in random order.

I define my character array (9 items) as the following: char arr[] = {'a', 'c', 'b', 'z', 'k', 'l', 'j', 'o', 'd'} From this array, I would like to create a 3x3 array, in which the characters are ...
3
votes
1answer
112 views

Why do we use architecture-specific types in C

I think that the type names in Rust are much better than the ones in C. I'd choose f64 over double and u32 over unsigned int or uint_32t any day. Is there any reason (other than tradition) to use ...
-5
votes
1answer
242 views

Why code in C instead of C++ [closed]

Why code in C? Isn't C++ basically C but with better features? Why do people still use C? Would it be easier to make a game with C or C++?
1
vote
1answer
52 views

Need info on malloc trace

When I try the below code I am not clearly able to analyze malloc api internal calls.What I am not clear is about the system call mmap is called only once for 2 or more malloc calls.If I am assigning ...
68
votes
13answers
103k views

Is the C programming language still used?

I am a C# programmer, and most of my development is for websites along with a few Windows application. As far as C goes, I haven't used it in a long time, as there was no need to. It came to me as a ...
10
votes
3answers
2k views

using unsigned integers in c, c++

I have a very simple question that baffles me for a long time. I am dealing with networks and databases so a lot of data I am dealing with are 32-bit and 64-bit counters (unsigned), 32-bit and 64-bit ...
3
votes
3answers
287 views

Are global variables okay to use in asynchronous programs?

This may be a stupid question, sorry. I've read about the drawbacks of global variables a lot on this site. I'm finally trying to increase my code quality for a large project that'll be reviewed by ...
122
votes
15answers
30k views

Why do people use C if it is so dangerous?

I am considering learning C. But why do people use C (or C++) if it can be used 'dangerously'? By dangerous, I mean with pointers and other similar stuff. Like the Stack Overflow question Why is ...
0
votes
4answers
507 views

Why use a higher level language? [closed]

A question that gets asked a lot is "Why use low level languages if you can code in high level languages more easily (and often tersely)?". I think the answers are fairly straight forward here, being ...
4
votes
2answers
122 views

A question about implementing objects in a language written in C

I'm fairly new to programming (about four months learning), and have decided to mess about with an attempt at writing a language in C for both fun and practice, and am wondering how objects are ...
61
votes
18answers
3k views

Why should I care about micro performance and efficency?

Many questions and answers on the C/C++ pages, specifically or indirectly discuss micro performance issues (such is the overhead of an indirect vs direct vs inline function), or using an O(N2) vs O(...
5
votes
3answers
8k views

How do we go from assembly to machine code(code generation)

Is there an easy way to visualize the step between assembling code to machine code? For example if you open about a binary file in notepad you see a textually formatted representation of machine code....
3
votes
2answers
138 views

Referential Transparency by using Zero References?

Referential Transparency is one of the corner stones of functional programming that allows us to apply equative reasoning to our code. However it does so at a cost to performance, by use of immutable ...
18
votes
2answers
5k views

Why does C use the asterisk for pointers? [closed]

I'm just now learning about C. I find it odd that the creators chose the asterisk (*) as the symbol for pointers rather than a symbol that actually looks like a pointer (->). Considering how ...