Hi,
I'm trying to map a C structure to Java using JNA. I came across something that I've never seen.
The struct definition is as follow,
struct op
{
unsigned op_type:9; //---> what does this means?
unsigned op_opt:1;
unsigned op_latefree:1;
unsigned op_latefreed:1;
unsigned op_attached:1;
unsigned op_spa...
Hi!
I am using BSD sockets in Ubuntu 9.10 to send UDP packets in broadcast with the following code:
sock_fd = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
//sock_fd=socket(AF_INET,SOCK_DGRAM,0);
receiver_addr.sin_family = PF_INET;
//does not send with broadcast in ad hoc
receiver_addr.sin_addr.s_addr ...
I know this is common in most languages, and maybe in C, as well. Can C handle separating several functions out to a separate file and having them be included?
The functions will rely on other include files, as well. I want the code to retain all functionality, but the code will be reused in several C scripts, and if I change it onc...
After five years of professional Java (and to a lesser extent, Python) programming and slowly feeling my CS education slip away, I decided I wanted to broaden my horizons / general usefulness to the world and do something that feels more (to me) like I really have an influence over the machine. I chose to learn C and Unix programming si...
Complete example:
#include <stdio.h>
void test(int arr[]) {
int arrSize = (int)(sizeof(arr) / sizeof(arr[0]));
printf("%d\n", arrSize); // 2 (wrong?!)
}
int main (int argc, const char * argv[]) {
int point[3] = {50, 30, 12};
int arrSize = (int)(sizeof(point) / sizeof(point[0]));
printf("%d\n", arrSize); // 3 (corr...
Hi there,
I'm back to C/C++ after some break.
I've a following problem:
I've a solution where I've several projects (compilable and linkable).
Now I need to add another project to this solution which depends on some sources from other projects.
My new project compiles without any problems (I've added "existing sources" to my project)....
There are 3 loops in C: for, while, do-while. What's the difference between them?
For example, it seems nearly all while statement can be replaced by for statement, right? Then, what's the advantage using while?
...
I have an application built with the MinGW C++ compiler that works something like grep - acommand looks something like this:
myapp -e '.*' *.txt
where the thing that comes after the -e switch is a regex, and the thing after that is file name pattern. It seems that MinGW automatically expands (globs in UNIX terms) the command line so ...
Lets say I have a vector of int which I've prefilled with 100 elements with a value of 0.
Then I create 2 threads and tell the first thread to fill elements 0 to 49 with numbers, then tell thread 2 to fill elements 50 to 99 with numbers. Can this be done? Otherwise, what's the best way of achieving this?
Thanks
...
Possible Duplicate:
casting char[][] to char** causes segfault?
I have a 2D array declared like this:
int arr[2][2]={ {1,2},{3,4}};
Now if I do:
int ** ptr=(int**) arr;
and:
cout<<**ptr;
I am getting a segmentation fault (using g++-4.0).
Why so? Shouldn't it be printing the value 1 (equal to arr[0][0])?
...
// the malloc style, which returns a pointer:
struct Cat *newCat = malloc(sizeof(struct Cat));
// no malloc...but isn't it actually the same thing? uses memory as well, or not?
struct Cat cat = {520.0f, 680.0f, NULL};
Basically, I can get a initialized structure in these two ways. My guess is: It's the same thing, but when I use mallo...
How can i convert from a Unicode path name (LPWSTR) to the ASCII equivalent? The library that gets called understands only c strings.
Edit:
Okay, I took the GetShortPathName and the WideCharToMultiByte suggestions and created that piece of code, i tested it with some folders containing Unicode characters in the path and it worked flawle...
I was wondering if i could create a object of some class if i have the name of the class
in a NSString.
I know this is possible in other languages like ActionScript, C# and PHP...
Something like this:
NSString *className = @"AwesomeViewController";
UIViewController *object = [[className alloc] initWithNibName:className bundle:nil];
...
I've found this in the CGPath.h header file. I'm curious what this const thing does?
typedef struct CGPath *CGMutablePathRef;
typedef const struct CGPath *CGPathRef;
My guess: If I typedef something as const, it's constant so immutable and can't be changed in any way. Does that make sense?
...
I want to know if a program that I am using and which requires a lot of memory is limited by the memory bandwidth.
When do you expect this to happen? Did it ever happen to you in a real life scenario?
I found several articles discussing this issue, including
http://www.cs.virginia.edu/~mccalpin/papers/bandwidth/node12.html
http://www...
enum ID // IDs
{
ID_HEADER = 0, // ID 0 = headers
#include "DATA.CSV"
ID_LIMIT
};
I inherited some code here.....
Looking at "DATA.CSV" I see all the ID's used to populate the enum in column B, along with other data.
My question:
How does the enum know that it is u...
Hi,
I am writing a C program which is a frontend to a myriad tools. This fronted will be launched like this:
my-frontend --action <AN ACTION>
As all the tools have the same prefix, let say for this example this prefix is "foo". I want to concatenate "AN ACTION" to this prefix and exec this (if the tool exists).
I have written someth...
I don't use correctly the format specifiers in C. A few lines of code:
int main()
{
char dest[]="stack";
unsigned short val = 500;
char c = 'a';
char* final = (char*) malloc(strlen(dest) + 6);
snprintf(final, strlen(dest)+6, "%c%c%hd%c%c%s", c, c, val, c, c, dest);
printf("%s\n", final...
Hello,
I'm attempting to utilize the socket.h functions within Windows. Essentially, I'm currently looking at the sample code at http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram. I understand that socket.h is a Unix function -- is there anyway I can easily emulate that environment while compiling this sample c...
I have a short integer variable called s_int that holds value = 2
unsighed short s_int = 2;
I want to copy this number to a char array to the first and second position of a char array.
Let's say we have char buffer[10];. We want the two bytes of s_int to be copied at buffer[0] and buffer[1].
How can I do it?
...