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

learn more… | top users | synonyms

0
votes
0answers
18 views

Emscripten - passing command line arguments

I have a C program "translated" (dont know what word is appropiate) to Javascript, so I can use it in node.js. C program consists of main that accepts command line parameters. I understand that I need ...
1
vote
1answer
96 views

Why did DirectDraw allow developers to directly write to GPU VRAM?

I'm reversing an old DirectX 7 game and I noticed that it sometimes uses Blt and BltFast but at other times, it locks the directdraw surface and directly writes to GPU VRAM. Why did developers take ...
-2
votes
0answers
38 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 ...
0
votes
2answers
68 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) { ...
3
votes
2answers
101 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
74 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 ...
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. ...
2
votes
5answers
216 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 ...
0
votes
1answer
82 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 ...
2
votes
6answers
355 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 ...
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
44 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 ...
-2
votes
0answers
78 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 ...
0
votes
1answer
132 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
206 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?
-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
1answer
94 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 ...
1
vote
3answers
248 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
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
95 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 ...
2
votes
0answers
30 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 ...
0
votes
0answers
54 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 ...
1
vote
3answers
154 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 ...
-5
votes
1answer
244 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
53 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 ...
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 ...
3
votes
1answer
113 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 ...
0
votes
4answers
508 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 ...
0
votes
3answers
313 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
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 ...
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 ...
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 ...
-5
votes
2answers
134 views

Why do I need these symbols to run a program? [closed]

#include <stdio.h> int main() { printf("Goodbye, World!"); return 0; } Why do I need #,<>, .h, and ()? What are their purposes?
-2
votes
1answer
176 views

Calling an entire script (in C) from another script (in C++)?

I am a very inexperienced programmer, so apologies if this is a stupid question to be asking. And similarly, if anyone answering could assume that I know basically nothing at all and treat me like an ...
13
votes
1answer
406 views

What is the history for naming constants in all uppercase?

What is the history behind the convention of naming constants in all uppercase? My intuition is that it started with the C preprocessor, where people developed a practice to name preprocessor macros ...
12
votes
4answers
3k views

Can a C struct behave like it had a function?

I use C and structs where a struct can have members but not functions. Assume for simplicity that I want to create a struct for strings that I name str and I want to be able to do str.replace(int i, ...
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 ...
3
votes
6answers
353 views

How efficient is malloc and how do implementations differ?

If I use malloc, does malloc always use the same algorithm regardless of what it is allocating or does it look at the data and select an appriopriate algorithm? Can we make malloc faster or smarter ...
2
votes
1answer
38 views

Configuration related defines in public header?

Suppose you're building some library, C or C++ doesn't really matter for this question, IMO. The features (or implementation thereof) depend on capabilities of the target system. A simple, probably ...
3
votes
2answers
142 views

memory allocation in C while calling function

I have a really basic question regarding how memory gets allocated in a code written in C. Let's say that I have something like this: int pointless(int a); int main(){ int num1,num2; num1=...
-1
votes
0answers
30 views

Help me understand this flow for recursive function [duplicate]

This recursive function blows my mind a bit because it executes the recursive calls until it hits 1. It returns n, but afterwards it does the multiplication below it four times and returns the final ...
2
votes
3answers
88 views

Difference between passing by values/address and returning a values through functions?

According to a book I read you can pass variables from one function to another by passing by value/address. When you pass by address it will no longer preserve the variable if it is changed in a ...
0
votes
0answers
48 views

GUI - engine data exchange, design with C, getters or struct pointers passing?

Having quite big codebase and external libraries, in C application, what would be pros and cons of two approaches (or suggest other): (assume that there are NONE api provided calls for this) Edit ...
0
votes
5answers
146 views

Range of values that can be stored in an integer type in C

C has family of integer types i.e {short, int, long, long long}. Any new programmer is likely to use int to represent integer variable in the application and since int type has 32 bit space with range ...
9
votes
1answer
167 views

Idiomatic wrapping of C++ template type API in C

I'm working on wrapping a C++ API which provides access to a data store (Hazelcast) in C functions, so that the data store can also be accessed from C-only code. The Hazelcast C++ API for the Map ...
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, ...
8
votes
3answers
1k views

Why isn't C's most basic printing function named `print` instead of `printf`? [duplicate]

AFAIK, C does not have a print function. The most basic we can get is printf. So, is there a reason why this function is not simply named print, instead of printf? Note that this question is about ...
14
votes
3answers
276 views

Supporting development for older OS

I am maintaining a large portion of legacy code, written in C. This code was initially written to be comiled against Windows 3 for Workgroups, and later a version for NT was created. This legacy ...
1
vote
2answers
180 views

What are microcontrollers programmed in most in industry? C or Assembly? [closed]

So recently in school we have started programming klm25z boards using ARM Assembly. I was wondering if in most industry jobs, microcontrollers are really programmed in assembly over C. It seems to ...