Tagged Questions

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
58 views

wrap mysql API for gui use

Some time ago now, I've written a command-line tool, that connects to MySQL, and through a series of commands, does all sorts of good stuff. It was originally intended to be used by myself and, ...
3
votes
2answers
403 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 ...
0
votes
2answers
140 views

What are and how do (data-) types work?

What is a "variable"/data type? How does a compiler / interpreter handle types? My specific concern has to do with the different types in lower and higher level languages. For instance in Python, ...
0
votes
1answer
165 views

distributed computing with remote hetrogenous machines

The way i am doing it now is using boost::asio TCP sockets handling everything manually with a main server that orchestrates the processes between the available machines, but the number of machines ...
-1
votes
1answer
122 views

A Server sending data to be processed to clients [closed]

About a year ago I had an idea in mind which was using my friends computers to help me process my data, so I programmed a socket server application with boost::asio, and gave the client part of it to ...
1
vote
3answers
190 views

Question about moving to embedded systems [closed]

I currently work as a .net developer and have coming up to 3 years experience in the industry as well as a degree in computer science specifically software engineering (I know that means nothing but ...
-1
votes
1answer
200 views

Is using non-standard single-line comments fine in C? [closed]

I noticed Visual C++ 2010 (my current environment) and XCode both allow non-standard single-line comments in my C programs. Since these are both my target platforms, I assume it's fine to use it? VC++ ...
0
votes
3answers
432 views

Why are there so few comments in C/C++ code? [closed]

I'm a web developer primarily, and I've been learning C/C++ and trying to get involved in some open source projects. Something I find very unusual is the lack of comments in C/C++ source code (I've ...
0
votes
2answers
515 views

Dynamic initialization, how does it work?

I have a question regarding dynamic initialization. Example code void main() { int a = 100; //Statement1 //Statement2 ... float b = 6.32987; //StatementA ... return; } The StatementA allocates ...
9
votes
3answers
601 views

How should I mark types in C and C++ programs?

In this answer of mine, I used _t at end of types, which ended at best, controversial. This is the practice I use in my current projects. typedef struct { int x; int y; } point_t; This was ...
1
vote
3answers
425 views

Can only integers be stored as register variables?

I am confused about this: what type of data can we store in register variables? I guess logically we can store any kind of data as register variables because they are variables, but really I am ...
2
votes
2answers
325 views

Drawback of mixing C++ code with C for performance purposes

Often you can see answers like “Avoid using C libraries in your C++ code“ or “This can be rewritten using STD/Boost in pure C++“. I understand C++ produces more maintainable code and has many ...
4
votes
1answer
217 views

“/*@null@*//*@out@*/” in C function declaration

In alloc.h of djbdns-1.05 there's the following code: extern /*@null@*//*@out@*/char *alloc(); My question is about the goofy-looking /*@null@*//*@out* “decorator.” I assume this is “just a ...
2
votes
3answers
464 views

How do you read this line of code?

Forgive me for my poor English, me and my friend were doing school homework, suddenly he asked me to read this line of code ptr = &array[1][1][1] (ptr is a pointer to an integer). He said ...
6
votes
5answers
675 views

Teaching a course on intro to programming, in C++: Do I teach C-style casts? [closed]

I'm currently redesigning a college level first semester graduate course on Intro to Programming, in C++. Note the comma; the course is introduction to programming, and C++ just happens to be the ...
6
votes
2answers
439 views

What's the reason for C standard to consider const-ness recursively?

The C99 standard says in 6.5.16:2: An assignment operator shall have a modifiable lvalue as its left operand. and in 6.3.2.1:1: A modifiable lvalue is an lvalue that does not have array ...
3
votes
2answers
235 views

Is it better to use an external variable or to pass around a pointer?

While writing in C, I have always wondered about when is the best time to use an external variable. I generally prefer to pass a pointer into a method. Is there a correct time to use an external ...
0
votes
2answers
255 views

Is it a good idea to const-qualify the fields of structure in C?

Consider the following program: #include <stdlib.h> #include <stdio.h> typedef struct S_s { const int _a; } S_t; S_t * create_S(void) { return calloc(sizeof(S_t), 1); } void ...
11
votes
7answers
545 views

What is idiomatic use of arbitrary blocks in C?

A block is a list of statements to be executed. Examples of where blocks come up in C are after a while statement and in if statements while( boolean expression) statement OR block if (boolean ...
6
votes
4answers
624 views

Is doing two things on one line always a bad practice?

int *itPins = pins; for(int i = 0; i < count; i++) { ConfigureGpifPinAsGpioOutput(itPins); itPins++; } I have the impression that doing two things in one line is bad practice. This is why ...
1
vote
5answers
285 views

How to alter the code at runtime in an interpreter?

While reading the difference between Compiler and interpreter , I found the following differences fromt he internet. Advantages of using compiler: Since compiler converts the program to native code ...
1
vote
2answers
253 views

Which is better: for valid buffer length?

This is a basic question. But, I think understanding this would be helpful to play with buffers in 'C'. Thanks. Scenario Just a sample snippet char *test_buff = (char *) malloc(512); //allocate 512 ...
2
votes
1answer
208 views

Should experimental code be preserved? [duplicate]

Am am working on a small project for a USB device firmware. I started from a working example, and am gradually adding new functionality and testing things. However, the new functionality is not all ...
0
votes
2answers
118 views

How much warnings in C to enable?

This is a tiny project of about 2000LOC. It is being compiled with -Wall. Now, I tried adding -Wextra. Two things happened: Some minor but valid warnings popped up, e.g. Comparing signed with ...
0
votes
3answers
538 views

Algorithm for recursive evaluation of postfix expressions

I'm reading Sedgewick's book on algorithms in C and I'm looking for an algorithm to evaluate postfix expressions (addition and multiplication only) without using a stack. I tried to implement one but ...
5
votes
2answers
413 views

Modularity and “encapsulation” in C

This applies to C (and probably to any other similar non-object oriented language). If I have a central data store and potentially concurrent access there are two ways I can see of protecting it. ...
2
votes
1answer
317 views

Clearing the lowest set bit of a number

I can see in this tutorial on bit manipulation, under the heading "Extracting every last bit", that - Suppose we wish to find the lowest set bit of x (which is known to be non-zero). If we ...
4
votes
3answers
214 views

adding array pointer in c

I am having problems understanding how this equation works in c: char *sum(char *a, int b) { return &a[b]; } printf("%d", sum(5, 4)); I understand how arrays work, and I understand how to ...
1
vote
1answer
598 views

What is the difference between string.c_str() and &string[0]?

What are the differences between string.c_str() and &string[0]? Regarding performance my guess is that &string[0] is a little faster than string.c_str() as it doesn't require a function call. ...
1
vote
4answers
674 views

Why languages that compile to C/C++ generate unreadable, cryptic code?

I'm willing to compile certain language to C or C++ for some speedups. My idea was, though, to generate readable code and use structures such std::vector and similar wherever I can, expecting CLANG to ...
0
votes
1answer
119 views

The keyword const and the linker file

If I declare in a header file, for example, extern unsigned long * Ptr; and the value of this pointer Ptr in the linker file. Will this adrress be 'constant'? Can I change its value ?
0
votes
2answers
282 views

Writing generic code when your target is a C compiler

I need to write some algorithms for a PIC micro controller. AFAIK, the official tools support either assembler or a subset of C. My goal is to write the algorithms in a generic and reusable way ...
2
votes
4answers
467 views

Why do we use to talk about addresses and memory of variable in C?

Why do we use to talk about addresses and memory of variable in C, where in other languages (like in Java, .Net etc) we do not talk about variable address and memory in a program, we will directly use ...
1
vote
1answer
105 views

Testing a codebase with sequential cohesion

I've this really simple program written in C with ncurses that's basically a front-end to sqlite3. I would like to implement TDD to continue the development and have found a nice C unit framework for ...
1
vote
3answers
4k views

Regarding little endian and big endian conversion

I have a query regarding big endian and little endian. Basically the conversion is used to reverse the byte order in memory . When we need to do the conversion, do we need convert each and every ...
1
vote
3answers
194 views

Requiring a specific order of compilaiton

When designing a compiled programming language, is it a bad idea to require a specific order of compilation of separate units, according to their dependencies? To illustrate what I mean, consider C. ...
0
votes
2answers
2k views

Can anyone explain representation of float in memory?

This is not duplicate question as I read the previous question. Can anyone help me in understanding how float values are stored in the memory . My doubt is here float values contain '.' (for example ...
1
vote
5answers
3k views

Reference vs dereference pointers in arguments C++/C

OK, I'm facing this all the time in many functions I write, which should I use? void sth(int* a) void sth(int& a) Which one is faster, regarding two separate occasions: a is a small variable or ...
4
votes
1answer
120 views

C programming multiple storage backends

I am starting a side project in C which requires multiple storage backends to be driven by a particular piece of logic. These storage backends would each be linked with the decision of which one to ...
0
votes
2answers
175 views

Perfomance of 8 bit operations on 64 bit architechture

I am usually a Python / Database programmer, and I am considering using C for a problem. I have a set of sequences, 8 characters long with 4 possible characters. My problem involves combining sets of ...
5
votes
1answer
483 views

Macro vs. Static functions in Header

for a lot of quick tasks where one could employ a function f(x,y), in plain C, macros are used. I would like to ask specifically about these cases, that are solvable by a function call (i.e. macros ...
12
votes
1answer
623 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 ...
0
votes
10answers
952 views

Why does the instruction “do” require a “while”? [closed]

Since this statement is so common: while (true) (Java) or while (1) (C) or sometimes for (;;) Why is there not a single instruction for this? I could think that an instruction that could do it ...
0
votes
1answer
239 views

How small is the footprint of a small C compiler?

This week I could optimize using a reduced C library that allowed a drastic shrinkage in code size - from about 60 K to about 6 K and then we could load the code in the 8 K on-chip memory of an FPGA ...
2
votes
2answers
191 views

How to pass parameters to a function in C

Suppose I'm writing a program in C in which several parameters are asked at the beginning of the execution to the user and then remain costant until the end. Now, I need to pass these parameters to ...
1
vote
1answer
120 views

structure problem in Relational DBMS creation

For learning and understanding purpose, I currently want to try to make a small relational DBMS with simple features like (for now) only sequential reading/writing and CREATE TABLE, INSERT, SELECT, ...
-1
votes
2answers
3k views

Want to create a simple gui app using C++ but dont know what to use [closed]

I have learned C++ to an intermediate point and now I'd like to create something beyond a console program. I would like to create a simple program that grabs info from specific text files and displays ...
2
votes
3answers
2k views

Is there any alternative to function pointers in c++?

I am a novice c++ programmer who kept an idea that function pointers are a thing of C and OOP in C++ does not recommend its usage. I know what I write here is vague/broad. But it will be great if ...
2
votes
2answers
241 views

When should I copy a pointer inside a function?

I'm trying to teach myself programming and I'd really appreciate some help with this issue. I've just read a tutorial on pointers but I have a problem with the example. The function copies one string ...
4
votes
3answers
2k views

Is it possible to combine C/C++ with web languages? [duplicate]

I would like to create a web application (meaning that will run from browser). The point is that I want to write just the UI in HTML5 + CSS + JS (or maybe even some PHP). On the other hand, I want to ...