Questions tagged [c]

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

Filter by
Sorted by
Tagged with
-1 votes
1 answer
172 views

How can we make a certain thing inbuilt in c language with our own header file?

I want to make the basic trigonometric functions in maths inbuilt functions using my own header file . so as the users can do trigonometry in c language compilers.
tania's user avatar
  • 11
1 vote
2 answers
271 views

How to handle enums in an indirection with functionpointers at ANSI-C?

Moinsen, I am somehow stucked in a design problem. Language is ANSI-C. Lets assume we have a tinkerbox of software-modules: one module for the logic Logic (at least) one module doing some logging ...
Oliver's user avatar
  • 143
23 votes
4 answers
6k views

How bad is it calling println() often than concatenating strings together and calling it once?

I know output to the console is a costly operation. In the interest of code readability sometimes it is nice to call a function to output text twice, rather than having a long string of text as an ...
Celeritas's user avatar
  • 595
2 votes
4 answers
2k views

Going through The C Programming Language K&R in Visual Studio [closed]

From what I have read, K&R seems to be a good place to start learning programming in general, and C programming specifically. However, I've just started the first chapter and I have a few ...
Steve's user avatar
  • 37
12 votes
5 answers
18k views

Why would a C executable be smaller when compared to C++ executable

I'm trying to understand why the output file sizes are significantly different when using a C and a C++ compiler. I was writing a small hello world program in C and C++, I noticed that in C version, ...
Hawk's user avatar
  • 359
3 votes
4 answers
20k views

usage of double pointers and n pointers?

I am familiar with basic C pointers. Just wanted to ask what is the actual use of double pointers or for that matter n pointer? #include<stdio.h> int main() { int n = 10 , *ptr , **ptr_ptr ;...
instinct's user avatar
  • 143
8 votes
1 answer
337 views

Suggested method for extracting a standalone C library from an existing R package?

My group has been developing an R package to simulate plant growth (see GitHub repository). The R package uses .Call to interface with C. We have decided that it would be worthwhile to create a ...
David LeBauer's user avatar
2 votes
3 answers
1k views

Transitioning from Java & C to C++

I learned Java and I'm pretty competent programming in it. I also learned C recently. I looked at a comparison between Java and C++ and I like C++'s features like operator overloading and its speed. ...
shoham's user avatar
  • 225
2 votes
3 answers
2k views

Understanding how variable assignment works

When I started learning C programming a few years ago, my tutor taught me similar to most of the tutors around the world. She said me the very basic things like any int datatype is of 2 bytes memory. ...
Ramvignesh's user avatar
1 vote
2 answers
165 views

Understanding Arithmetic In C

I have an embarrassingly simple question, but I need to make sure I understand this correctly. I have a *.c file with the following line: CSRConstant = 2*macroParticleCharge*particleCharge/pow(3*...
user1886681's user avatar
14 votes
4 answers
5k views

Why can't arrays be passed as function arguments in C?

Following this comment, I've tried to google why, but my google-fu failed. Comment from link: [...] But the important thing is that arrays and pointers are different things in C. Assuming you're not ...
Florian Margaine's user avatar
2 votes
2 answers
207 views

gcc -S seems a bit misshapen with shifting and ANDing bits

Example: int c = 4; int p = 5; if (p & (1 << c)) printf("ok\n"); else printf("nop\n"); gcc -S: movl -4(%rbp), %eax /* eax holds the variable c */ movl -8(%rbp), %edx /* ...
nobby's user avatar
  • 123
2 votes
3 answers
434 views

Use of malloc in C [closed]

Is it necessary to call free function every time we use malloc in C. I am asking this because I have seen many times that it is not called . Thank you
Supreet's user avatar
  • 23
1 vote
1 answer
984 views

How to check the space complexity of this program?

I have written my version of strstr function in c. I am using a temporary array of size 26. Then is the space complexity O(1) or O(n)? This is my code : void strcheck(char t[], int n, char p[], int ...
coder005's user avatar
5 votes
4 answers
2k views

Why is it called a memory leak?

I am a hobbyist programmer, bit of a stickler for terminology, currently learning C and recently came across the concept of Memory Leak. Now, I do understand what it means. Dynamic memory allocated to ...
user1720897's user avatar
1 vote
1 answer
905 views

Memory read/write access efficiency

I've heard conflicting information from different sources, and I'm not really sure which one to believe. As such, I'll post what I understand and ask for corrections. Let's say I want to use a 2D ...
wolfPack88's user avatar
6 votes
1 answer
14k views

Global variable in a Linux shared library

Suppose we have the following setup under Linux, .so library named "libcnt.so" and 3 user space apps: "app1", "app2", "app3". This library does 1 simple thing, it says to the app (app dynamically ...
user3730495's user avatar
11 votes
1 answer
4k views

Why is the function called lseek(), not seek()?

The C function for seeking in a file is called lseek(). Why ins't it called just seek()?
Niccolo M.'s user avatar
4 votes
3 answers
514 views

Organization of DLL linked functions

This is a code organization question. I got my basic code working but when I expand it, it will be terrible. I have a DLL which I don't have a .lib for. Therefore I have to use the whole LoadLibrary()...
m25's user avatar
  • 153
1 vote
3 answers
2k views

Parsing mathematical expressions with two values that have parentheses and minus signs

I'm trying to parse equations like the ones below, which only have two values or the square root of a certain value, from a text file: 100+100 -100-100 -(100)+(-100) sqrt(100) by the minus signs, ...
user45921's user avatar
1 vote
1 answer
941 views

Are there theoretical reasons why arrays in C take less RAM than Java?

My experience is that Java requires about twice as much RAM compared to C (comparing char arrays or other comparisons). I also read in a hardware book that Java takes about twice RAM than C. Is is ...
Niklas Rosencrantz's user avatar
6 votes
3 answers
4k views

Why are there two different kinds of linking, i.e. static and dynamic?

I've been bitten for the n-th time now by a library mismatch between a build and deployment environment. The build environment had libruby.so.2.0 and the deployment environment had libruby.a. One ruby ...
user avatar
8 votes
1 answer
2k views

Why are most GNU's software written in C [closed]

I am a Java developer, and I rarely write GUI program in C. However, I noticed that many GNU's projects, such as PSPP, R, Dia, etc., are written in C, instead of Java or C++. I personally don't mind ...
user avatar
-1 votes
4 answers
2k views

Benefits of porting C library to C++ [closed]

Say we take any C library such as libpng or libvorbis and convert it so that it compiles as C++ (only the minimum changes to make it compile as C++ code). Can the compiler do extra optimizations when ...
links77's user avatar
  • 117
1 vote
2 answers
560 views

"bug" in C++11 text by Stroustrup?

I found an apparent contradiction in the c++ text having to do with the result of the c_str() function operating on std:strings (in my copy, the definition and contradiction are on p1040). First it ...
Astara's user avatar
  • 187
1 vote
1 answer
234 views

Should I implement a function or a method?

Once in a while I encounter a C function in my colleagues' code. Mostly it is in some helpful objective categories, and those functions are mostly an internal calculation of something or a ...
Earl Grey's user avatar
  • 628
19 votes
4 answers
95k views

How are negative signed values stored?

I was watching this video on the maximum and minimum values of signed integers. Take an example of a positive signed value - 0000 0001 The first bit denotes that the number is positive and the last ...
discussedtree's user avatar
16 votes
1 answer
1k views

How to effectively cooperate in a team having mixed background/mindset regarding OOP? [duplicate]

I've been recently assigned for a new high-performance C++ project (finance) together with 3 other guys who, like, me, refer to themselves as "primarily C/C++ programmers", meaning, all of us have ...
haelix's user avatar
  • 270
32 votes
7 answers
10k views

Writing in C for Performance? [closed]

I know I have quite frequently heard that C typically has a performance advantage over C++. I didn't really think anything else of it until I realized that MSVC doesn't even seem to support the newest ...
Daniel Underwood's user avatar
1 vote
3 answers
11k views

comparison of floating point numbers vs. comparsion of Integers in C [closed]

Does comparison of floating point numbers takes (considerably) longer time than comparison of Integers in C? I just wrote a C program of heap sort to sort floating point numbers. I am on ubuntu 14....
Nullpointer's user avatar
6 votes
3 answers
724 views

Is allocating objects from a memory-pool a security anti-pattern?

In the wake of the heartbleed bug, OpenSSL has been rightly critizised for using its own freelist. With plain-old malloc, the bug would have almost certainly been found long ago. However, some kind ...
Adrian Ratnapala's user avatar
0 votes
0 answers
99 views

how to find average bits per symbol using huffman code? [duplicate]

I'm trying to write a program in c for Huffman coding, but i stack.In input i have: Sample input: 4 //here i scan how many letters i have A 00 // and for everyone i scan how they are coded in ...
Maria's user avatar
  • 29
82 votes
10 answers
24k views

Why do C arrays not keep track of their length?

What was the reasoning behind not explicitly storing an array's length with an array in C? The way I see it, there are overwhelming reasons to do so but not very many in support of the standard (C89)....
VF1's user avatar
  • 1,891
3 votes
0 answers
1k views

using flat file vs sqlite db for frequent data grabbing in a cron job

I have some automated task to be done using certain types of logs generated on the server end of each day. Log files contains specific machine identification "MAC" that is to be re-written in to ...
Muneer's user avatar
  • 260
1 vote
1 answer
292 views

How to implement an algorithm out-of-core?

I want to implement a parallel clustering algorithm "out-of-core" in CUDA. My CPU has 12GB of RAM and GPU has 4GB of it. What I want is that the entire dataset should be on the disk, and I can pick ...
pymd's user avatar
  • 111
5 votes
1 answer
221 views

At ping, why do we have to do array copying instead of passing on the source array that the client sent to us?

So I have been googling about this OpenSSL heart-bleed thing and somehow sees that it is caused by the heartbeat extension which requires client to ping the server to show its aliveness and it all ...
vcharlie's user avatar
3 votes
2 answers
1k views

Advice for simple communication protocol (iPod and Arduino)

I connected iPod with Arduino using serial (UART) connection. Arduino sends 0-1023 number (so it's two bytes) as it's samples light sensor value. I'm asking about advice about simple and reliable ...
kesrut's user avatar
  • 175
4 votes
2 answers
2k views

How to manage memory in C interface for C++ implementation considering c++11?

I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but ...
griotspeak's user avatar
3 votes
4 answers
2k views

Best and safest API for a function which fills a buffer with variable-length data

I have a function which receives a buffer and returns some data in the buffer. The data can be smaller than the buffer capacity. Which is the best and safest API for this? int fn(void *buffer, ...
Conrado's user avatar
  • 131
0 votes
2 answers
89 views

Use one or multiple files for graphics properties?

I'm creating a 2D game in plain ANSI-C using SDL2. I'm planning to let users create their own graphics. So, to achieve this, I'll use an information file which will hold some data such as Width, ...
cdonts's user avatar
  • 103
0 votes
3 answers
122 views

Looking for a certain datatype if it exists

I'm looking for the kind of a certain datatypes. The main idea of this datatype is to describe a productionline containing several steps. Each step should be represented as a "vertex" containing an ...
xamiax's user avatar
  • 51
0 votes
5 answers
443 views

What conclusion to be drawn from no difference in generated assembly from 2 rather different programs?

I might not have had a counterexample when I got the reply "A pointer is just an address, what's the difficulty?" but I didn't really buy such a simple explanation and at assembly code it's not ...
Niklas Rosencrantz's user avatar
14 votes
2 answers
9k views

Are (C) object files created with different compilers binary-compatible?

I understand that C++ compilers are not compatible with each other. However, I was unable to find anything on this topic for C in particular. I know that the C standard leaves a lot of room for ...
Doval's user avatar
  • 15.4k
0 votes
1 answer
2k views

Algorithm for base-conversion in C?

I put in this code which does what it's supposed to do, but perhaps there is a better or more general approach? I'm converting a 4-digit base 10 number e.g. "11" to base 16 e.g. "17" (which gets ...
Niklas Rosencrantz's user avatar
1 vote
3 answers
2k views

How can I handle this string concatenation in C in a reusable way

I've been writing a small C application that operates on files, and I've found that I have been copy+pasting this code around my functions: char fullpath[PATH_MAX]; fullpath[0] = '\0'; strcat(...
ellipse-of-uncertainty's user avatar
2 votes
2 answers
4k views

Representing a deck of cards in C (not C++)

So far my best ideas have been as fallows A) Represent a "card" in one structure and have a "deck" in another a deck being an array of 52 cards and a card being 2 chars one for and rank one for suit. ...
Joe's user avatar
  • 359
3 votes
4 answers
4k views

How do you call one program from another?

What I'm wondering is how running programs communicate with each other, and if someone could post some sample code for how to do this, so I can try it out myself, just for educational purposes. For ...
Nickolai's user avatar
  • 141
13 votes
3 answers
20k views

What is the underlying mechanism behind va_list and where is it defined?

http://www.cplusplus.com/reference/cstdarg/va_list/ According to the above link, va_list is an argument or parameter used in some macros - va_start, va_arg, va_end. These macros are present in the ...
aste123's user avatar
  • 419
1 vote
1 answer
345 views

What is this programming style? "Monoid-ic"?

In a moderately old blog post, Conal Elliot makes an interesting (if less than serious) argument that C is a purely functional language, by drawing a parallel between the combination of the C ...
Alex Celeste's user avatar
6 votes
3 answers
1k views

How to extract the active code path from a complex algorithm

I have been puzzled lately by an intruiging idea. I wonder if there is a (known) method to extract the executed source code from a large complex algorithm. I will try to elaborate this question: ...
user3417322's user avatar

1
14 15
16
17 18
27