Please see the simple code below:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
unsigned long currentTrafficTypeValueDec;
long input;
input=63;
currentTrafficTypeValueDec = (unsigned long) 1LL << input;
cout << currentTrafficTypeValueDec << endl;
printf("%u \n", currentTrafficT...
I am using C and Grand Central Dispatch to parallelize some heavy computations. How can I get the number of threads used by GCD? Also is it possible to know on which thread a piece of code is currently running on? Basically I'd like to use sprng (parallel random numbers) with multiple streams and for that I need to know what stream id to...
Hey!
Just got today these ones:
http://www.pearl.de/a-PE5858-1413.shtml
I want to start programming with these, but I can't find anything usable. I'm using Ubuntu Jaunty 9.04. The Problem is that I couldn't find much samples and modules etc. for my modell.
...
Hi,
In an if statement with multiple conditions is second executed if the outcome is clear after checking the first condition?
example:
if(i>0 && array[i]==0){
}
If I swap the conditions a seg fault may occur for negative values of i but this way the memory debugger doesn't find a problem. Can I be sure that this works always or do ...
Hi,
I'm just starting to study C. I have a program that prints a menu and let users choose what to do step by step. Now I would like to return to the main menu whenever the user enters an empty line, but how can I do that?
I think I can make a function that return the program to the main menu, but when to call that function? I know it's...
Hi, I've run into an issue porting a codebase from linux (gcc) to windows (msvc). It seems like the C99 function vsscanf isn't available and has no obvious replacement.
I've read about a solution using the internal function _input_l and linking statically to the crt runtime, but unfortunately I cannot link statically since it would mess...
Hi - I'm working on processing the amplitude of a wav file and scaling it by some decimal factor. I'm trying to wrap my head around how to read and re-write the file in a memory-efficient way while also trying to tackle the nuances of the language (I'm new to C). The file can be in either an 8- or 16-bit format. The way I thought of doi...
I have a function which takes a block of data and the size of the block and a function pointer as argument. Then it iterates over the data and performes a calculation on each element of the data block.
The following is the essential outline of what I am doing:
int myfunction(int* data, int size, int (*functionAsPointer)(int)){
//wa...
I create a 2D dynamic array:
a = (int**)calloc(n-1, sizeof(int));
for(i = 0; i < (n-1); i++)
a[i] = (int*)calloc(n, sizeof(int));
Then I need to change its size (add new line):
a = (int**)realloc(a, n);
a[n] = (int*)calloc(n, sizeof(int));
But when i want to print my array,
void Print(void){
int i, j;
for(i = 0; i < (...
I was wondering if there was any resources available online that explains what happens with something, like printf of C, that explains what's going on in the very low level (BIOS/kernel calls)
...
I have a CGI application written in C. When I POST (delete data) to the cgi app from the html form, the action is correctly executed on the server but the page does not refresh after the POST. It does flicker, but displays the non-updated page. I then have to hit the browsers refresh to see the correct updated html page (showing data has...
Friends,
I have a strange need and cannot think my way through the problem. The great and mighty Google is of little help due to keyword recycling (as you'll see). Can you help?
What I want to do is store data of multiple types in a single column in MySQL.
This is the database equivalent to a C union (and if you search for MySQL and...
I'm not particularly knowledgable about programming and I'm trying to figure out how to get a precise value calculated in a C program. I need a constant to the power of negative 7, with 5 significant figures. Any suggestions (keeping in mind I know very little, have never programmed in anything but c and only during required courses that...
I have an assignment in which I need to declare a pipe in a header file. I really have no idea how to do this. It might be a really stupid question and I might be missing something obvious. If you could point me in the right direction I would greatly appreciate it.
Thanks for your time.
EDIT:
Sorry about the question being so vague. M...
I have two C files and one header that are as follows:
Header file header.h:
char c = 0;
file1.c:
#include "header.h"
file2.c:
#include "header.h"
I was warned about 'duplicate definition' when compiling. I understand the cause as the variable c is defined twice in both file1.c and file2.c; however, I do need to reference the h...
Why won't the following C code compile? It seems like it should just change the pointers address but it throws an error.
int x[10];
int y[10];
y=x;
...
I want to make a simple macro with #define for returning the smaller of two numbers.
How can i do this in C ? Suggest some ideas, and see if you can make it more obfuscated too.
...
Suppose that I have those three files:
a.h
//a.h header
#include <stdio.h>
int int_variable;
void a_f()
{
printf("int_variable: %d\n", int_variable)
int_variable++;
}
b.h
//b.h header
#include <stdio.h>
int int_variable;
void b_f()
{
printf("int_variable: %d\n", int_variable)
int_variable++;
}
main.c
//main.c
#inclu...
I have a function that makes a series of calls to sscanf() and then, after each, updates the string pointer to point to the first character not consumed by sscanf() like so:
if(sscanf(str, "%d%n", &fooInt, &length) != 1)
{
// error handling
}
str+=length;
In order to clean it up and avoid duplicating this several times over, i'd l...
struct struct0 {
int a;
};
struct struct1 {
struct struct0 structure0;
int b;
} rho;
&rho->structure0; /* Reference 1 */
(struct struct0 *)rho; /* Reference 2 */
(struct struct0)rho; /* Reference 3 */
From reference 1, does the compiler take the address of rho, and then access structure0, or vice-versa?
What does the line at ...