Tagged Questions
C is a general-purpose computer programming language used for operating systems, games and other high performance work.
5
votes
2answers
99 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 ...
0
votes
4answers
783 views
Going through The C Programming Language K&R in Visual Studio
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 ...
-1
votes
1answer
79 views
Programmer Analyst vs Software Engineer [on hold]
So I've heard the job title "programmer analyst" and "business analyst" thrown around for software jobs recently.
How do the responsibilities of Programmer Analysts, Business Analysts and Software ...
-4
votes
1answer
80 views
Best book to learn how to program in C? [on hold]
I've learnt the basics of C; most of the syntax( variables, input and output, operators, functions, if/else, switch-case, arrays, pointers, chars and strings, file read and write, structs, enums, ...
-2
votes
0answers
71 views
How can I improve the following code in terms of faster execution? [migrated]
The problem is described here - Aaah!.
My source code for the problem is below. I one of the fast running codes, but not the best. What changes can I make so as to improve the efficiency of the code.
...
1
vote
4answers
408 views
C executable smaller compared to C++ executable
I was writing a small hello world program in C and C++, I noticed that in C version, the size of the executable was 93.7KB and in C++, the size of the same hello world program was 1.33MB. I am not ...
0
votes
3answers
111 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 ;
...
0
votes
0answers
4 views
What happens when there is multiple expressions in the condition part of a for loop seperated by commas? [migrated]
I have an infinite loop here, but why?
int end = 5;
for(int i = 0; i < end, printf("at condition i=%d\n",i); ++i)
{
printf("inside i=%d\n",i);
}
6
votes
1answer
143 views
+100
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 ...
-1
votes
0answers
36 views
How to get the desired output with a multiplication table [closed]
A tutorial question is asking to write a program using nested loops that prints out a multiplication table in this form:
The user has to input an integer and the multiplication table for that ...
-2
votes
0answers
55 views
Recommendation for the structure of a General purpose Embedded Development training [closed]
I've been assigned a task at work to put together a general training for Embedded Development for our new colleagues, but I don't have experience with making trainings.
The target audience of the ...
-1
votes
0answers
6 views
C sorting problem [closed]
When I'm with a similar code, with random "IDs" and "Balances", after being seeded by time, the code works just fine. Whats wrong with this code?
#include <stdio.h>
main()
{
int idSearch;
...
-4
votes
0answers
85 views
Fear of web developement [closed]
I start programming at the age of 15 with php my first real language. Since the age of 16 I've learned more about php and web-developement in general. Even though I was warned by many people that php ...
-4
votes
0answers
144 views
What if I learn Java and then it becomes obsolete? [closed]
How long do you think Java and C will be significant languages to learn?
What if those languages are just not powerful enough for the new coming technological age if there is one? If this is the wrong ...
-4
votes
0answers
35 views
Where do I get the latest man pages for c programming? [closed]
I want to cover the whole scope of c programming.
Also do you know any good books or software projects? Thanks
0
votes
0answers
74 views
Different ways of addressing pointers C/C++ [migrated]
I'm a little confused about accessing specific addresses using c style pointers.
I have a 32 bit chip which I'm tryin to program. I need to flip some bits or whatever in ram. The following solution ...
2
votes
3answers
223 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.
...
2
votes
2answers
223 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. ...
1
vote
2answers
140 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 = ...
9
votes
2answers
561 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 ...
2
votes
1answer
46 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 /* ...
0
votes
3answers
133 views
Use of malloc in C
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
1
vote
1answer
72 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 ...
0
votes
2answers
241 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 ...
1
vote
1answer
95 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 ...
0
votes
1answer
80 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 ...
4
votes
1answer
238 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()?
3
votes
3answers
152 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 ...
0
votes
0answers
65 views
Parsing mathematical experssions 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 ...
1
vote
1answer
180 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 ...
2
votes
3answers
155 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 ...
4
votes
1answer
533 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 ...
-2
votes
4answers
178 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 ...
0
votes
0answers
18 views
Length of array (C) [migrated]
I have an array of 10 elements. This array stocks some informations but last information is ended by an symbol "END" (which is -1).
for exemple:
array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = ...
1
vote
2answers
303 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 ...
1
vote
1answer
115 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 ...
0
votes
3answers
123 views
How are negative signed values stored? [duplicate]
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 ...
15
votes
1answer
541 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 ...
20
votes
7answers
3k 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 ...
0
votes
3answers
161 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 ...
3
votes
3answers
96 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 ...
0
votes
0answers
18 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 ...
54
votes
10answers
6k 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 ...
1
vote
0answers
100 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 ...
1
vote
1answer
134 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 ...
5
votes
1answer
160 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 ...
3
votes
2answers
99 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 ...
3
votes
2answers
151 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 ...
2
votes
3answers
65 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, ...
0
votes
2answers
56 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, ...