question stringlengths 25 894 | answer stringlengths 4 863 |
|---|---|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
So I've seen it everywhere in apps/... |
Create aUILabelto display the score, and use anNSTimerto update theUILabel'stextproperty. Apple doesn't ship a class that will do it all for you.
|
I have not coded in c in a while, and I never was very good with pointers.
i have this beginning for main.
```
int main(int argc, char *argv[])
```
I need to be able to make a copy of the *argv[] in a global scope to allow multiple threads to access it, Is there a fast/easy way to do this?
|
You don't need tocopytheargvarray (given tomain). You only need to transmit the pointer to it to your threads. This is quite easy (by passing it thru arguments, or by having some global variable containing it).
|
consider a function like
```
char* strcpy (char* destination, const char* source);
```
The given value at (address) source is const because the author of the function wants to show that the value of source will not be changed by strcpy. The pointer itself is not changed by strcpy to. Why not to write
```
char* strc... |
The pointer itself is passed by value, so there's no point.
|
I have an attributed string that I want to draw bottom-aligned into a rectangular path, using Core Text. Is there a way to get CTFrameSetter / CTFrame to do this, or do I need to do it manually? The manual way being:
Figure out the height of the frame using CTFramesetterSuggestFrameSizeWithConstraintsAdjust the heigh... |
You'll have to do it manually.
```
CGRect boundingBox = CTFontGetBoundingBox(font);
//Get the position on the y axis
float midHeight = self.frame.size.height / 2;
midHeight -= boundingBox.size.height / 2;
CGPathAddRect(path, NULL, CGRectMake(0, midHeight, self.frame.size.width, boundingBox.size.height));
```
Refer... |
I see this line in C:
```
#define log(format, args...) snprintf(buffer + strlen(buffer), 1023 - strlen(buffer), format, ##args);
```
What does the double pound / hash mean before the last param insnprintf()?
|
In standard C, the "##" is for concatenating tokens together within a macro. Here, this macro is not in standard C, but in "Gnu C", the dialect implemented byGCC. The "##" is used to remove the comma if the extra arguments (inargs) turn out to be empty. Seethe GCC manual.
|
(I have just answered this question after searching for a while, so I am asking and answering this question here for it to be here when it's needed. There are similar, but not quite the same, questions.)
|
Cast it toint. This can be consumed by astringstreamor otherwise converted forstringuse.
Wherecolourwas astruct SDL_ColorcontainingUint8(a defined alias foruint8_t) members, the solution was
```
stringstream ss << "[colour=" << (int)colour.r << ", " << (int)colour.g << ", " << (int)colour.b << "; light=" << light <<... |
I've been learning about C recently, and I've encountered something which I can't seem to find a good answer to.
In my code I might have:
```
struct randomStruct a;
struct secondStruct array[5];
struct structyStruct q = { 17, "Hey yo", {123,123}};
```
But in memory, they might be stored as:
```
q, a, array
```
Wh... |
What you are seeing happens because ofthe direction of the stack growth.
The standard says nothing whatsoever about addresses of automatic variables. Thus it's not required that a relation between variables' addresses exists.
|
This question already has answers here:Why are these constructs using pre and post-increment undefined behavior?(15 answers)Closed8 years ago.
```
int main(void)
{
int i = 0;
i = ++i % 3;
return 0;
}
```
I compile it like this:
```
$ gcc -Wall main.c -o main
main.c: In function ‘main’:
main.c:4: warning... |
Because you are modifying the value ofitwice without an interveningsequence point. It'sundefined behavior.
|
I have a C application running on Linux and it processes thousands of messages...but not whe I run the application after a couple minutes it brings up the following error:
sh: error while loading shared libraries: libc.so.6: cannot open shared object file: Error 24
The application is doing about 30 messages per seco... |
Errno 24 means: "Too many open files".
After some thoughts I think the application opens a file, which is not allowed by the system anymore. The application can not handle this situation correctly, and crashes with a segmentation fault. Are the return values from the "open" system call checked correctly everywhere?
|
I want to turn off the buffering for the stdout for getting the exact result for the following code
```
while(1) {
printf(".");
sleep(1);
}
```
The code printf bunch of '.' only when buffer gets filled.
|
You can use thesetvbuf function:
```
setvbuf(stdout, NULL, _IONBF, 0);
```
Here're some other links to the function.
POSIXC/C++
|
I have manyjoinablethreads that at some point need to all stop. The threads are pthread, but are created through RTAI's user-space interface (never mind the RTAI though).
For each thread I have a variable that I can set to tell them to quit. So what I do is:
set that variable for each thread so that they stopWait at... |
Killing a thread doesn't change whether you should join it or not. If
the thread hasn't been detached, then you need to join it, or you will leak
resources in the system.
|
i have a piece of code in C .But i am not able to understand its output
```
#include<stdio.h>
main()
{
char a1[20];
char a2[30];
char a3[40];
scanf("%s",&a1);
gets(a2);
fgets(a3,sizeof(a3),stdin);
printf("%d,%d,%d\n",strlen(a1),strlen(a2),strlen(a3));
}
```
When i enter my input like
```
amit
singh
```
output c... |
input is"amit\nsingh\n"thescanfconsumes "amit" (and writes that intoa1)thegetsconsumes "\n" (and writes empty string toa2)thefgetsconsumes "singh\n" (which it writes toa3)
The output is correct.
Do notEVERusegets!
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fscanf.htmlhttp://pubs.opengroup.org/onlinep... |
I am writing a program that gets a filepath-name from the command-line and then proceeds to open the file. My question is: Is it possible to create a string, the moment the user gives the input, that would be exactly the size needed for the filepath to fit into it? If not, what would be the ideal size for the non-dyna... |
Per the C standard the FILENAME_MAX macro (defined in stdio.h) specifies either the maximum or recommended length of file names (quote:222) If the implementation imposes no practical limit on the length of file name strings, the value of FILENAME_MAX should instead be the recommended size of an array intended to hold ... |
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed10 years ago.Improve this question
I currently need to resolve an issue with duplicated logic on web-based monitoring ... |
The answer iscompletely dependent on your problem domain. Java has libraries available for reading XML, JSON and a host of other protocols.
You need to be asking questions like:
How much data will I be producing?Does the data need to be human-readable?Is storage size an issue?Is the time to read / write the data an... |
I want to change the background texture of a Gobject clutter actor whenever it is highlighted. Is there any way i can replace the texture during runtime ?
|
you can use theclutter_texture_set_*family of functions, like:
clutter_texture_set_from_fileclutter_texture_set_from_rgb_dataclutter_texture_set_area_from_rgb_data
all documented here:http://developer.gnome.org/clutter/stable/ClutterTexture.html
|
I am dumping a class in Windbg (bydt) and for aboolmember I see the valuefffffffffffffff8(bin: ...1111111111111111000).It is a valid value (including padding) or not?
PS: i'm investigating a dump that may be a memory corruption so .. can't be sure.PS2: my bool is in class between apointerand asize_t. Compiled as rele... |
It's not a validboolvalue --boolshould only show up as0or1. Since you're seeing 0xf8, the memory is either not initialized or overwritten. (Note that for some reason, WinDbg will only read a single byte and then sign-extend it to 64-bits.)
|
I see this line in C:
```
#define log(format, args...) snprintf(buffer + strlen(buffer), 1023 - strlen(buffer), format, ##args);
```
What does the double pound / hash mean before the last param insnprintf()?
|
In standard C, the "##" is for concatenating tokens together within a macro. Here, this macro is not in standard C, but in "Gnu C", the dialect implemented byGCC. The "##" is used to remove the comma if the extra arguments (inargs) turn out to be empty. Seethe GCC manual.
|
(I have just answered this question after searching for a while, so I am asking and answering this question here for it to be here when it's needed. There are similar, but not quite the same, questions.)
|
Cast it toint. This can be consumed by astringstreamor otherwise converted forstringuse.
Wherecolourwas astruct SDL_ColorcontainingUint8(a defined alias foruint8_t) members, the solution was
```
stringstream ss << "[colour=" << (int)colour.r << ", " << (int)colour.g << ", " << (int)colour.b << "; light=" << light <<... |
I've been learning about C recently, and I've encountered something which I can't seem to find a good answer to.
In my code I might have:
```
struct randomStruct a;
struct secondStruct array[5];
struct structyStruct q = { 17, "Hey yo", {123,123}};
```
But in memory, they might be stored as:
```
q, a, array
```
Wh... |
What you are seeing happens because ofthe direction of the stack growth.
The standard says nothing whatsoever about addresses of automatic variables. Thus it's not required that a relation between variables' addresses exists.
|
This question already has answers here:Why are these constructs using pre and post-increment undefined behavior?(15 answers)Closed8 years ago.
```
int main(void)
{
int i = 0;
i = ++i % 3;
return 0;
}
```
I compile it like this:
```
$ gcc -Wall main.c -o main
main.c: In function ‘main’:
main.c:4: warning... |
Because you are modifying the value ofitwice without an interveningsequence point. It'sundefined behavior.
|
I have a C application running on Linux and it processes thousands of messages...but not whe I run the application after a couple minutes it brings up the following error:
sh: error while loading shared libraries: libc.so.6: cannot open shared object file: Error 24
The application is doing about 30 messages per seco... |
Errno 24 means: "Too many open files".
After some thoughts I think the application opens a file, which is not allowed by the system anymore. The application can not handle this situation correctly, and crashes with a segmentation fault. Are the return values from the "open" system call checked correctly everywhere?
|
I want to turn off the buffering for the stdout for getting the exact result for the following code
```
while(1) {
printf(".");
sleep(1);
}
```
The code printf bunch of '.' only when buffer gets filled.
|
You can use thesetvbuf function:
```
setvbuf(stdout, NULL, _IONBF, 0);
```
Here're some other links to the function.
POSIXC/C++
|
I have manyjoinablethreads that at some point need to all stop. The threads are pthread, but are created through RTAI's user-space interface (never mind the RTAI though).
For each thread I have a variable that I can set to tell them to quit. So what I do is:
set that variable for each thread so that they stopWait at... |
Killing a thread doesn't change whether you should join it or not. If
the thread hasn't been detached, then you need to join it, or you will leak
resources in the system.
|
i have a piece of code in C .But i am not able to understand its output
```
#include<stdio.h>
main()
{
char a1[20];
char a2[30];
char a3[40];
scanf("%s",&a1);
gets(a2);
fgets(a3,sizeof(a3),stdin);
printf("%d,%d,%d\n",strlen(a1),strlen(a2),strlen(a3));
}
```
When i enter my input like
```
amit
singh
```
output c... |
input is"amit\nsingh\n"thescanfconsumes "amit" (and writes that intoa1)thegetsconsumes "\n" (and writes empty string toa2)thefgetsconsumes "singh\n" (which it writes toa3)
The output is correct.
Do notEVERusegets!
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fscanf.htmlhttp://pubs.opengroup.org/onlinep... |
I am writing a program that gets a filepath-name from the command-line and then proceeds to open the file. My question is: Is it possible to create a string, the moment the user gives the input, that would be exactly the size needed for the filepath to fit into it? If not, what would be the ideal size for the non-dyna... |
Per the C standard the FILENAME_MAX macro (defined in stdio.h) specifies either the maximum or recommended length of file names (quote:222) If the implementation imposes no practical limit on the length of file name strings, the value of FILENAME_MAX should instead be the recommended size of an array intended to hold ... |
Closed. This question isopinion-based. It is not currently accepting answers.Want to improve this question?Update the question so it can be answered with facts and citations byediting this post.Closed10 years ago.Improve this question
I currently need to resolve an issue with duplicated logic on web-based monitoring ... |
The answer iscompletely dependent on your problem domain. Java has libraries available for reading XML, JSON and a host of other protocols.
You need to be asking questions like:
How much data will I be producing?Does the data need to be human-readable?Is storage size an issue?Is the time to read / write the data an... |
I want to change the background texture of a Gobject clutter actor whenever it is highlighted. Is there any way i can replace the texture during runtime ?
|
you can use theclutter_texture_set_*family of functions, like:
clutter_texture_set_from_fileclutter_texture_set_from_rgb_dataclutter_texture_set_area_from_rgb_data
all documented here:http://developer.gnome.org/clutter/stable/ClutterTexture.html
|
I am dumping a class in Windbg (bydt) and for aboolmember I see the valuefffffffffffffff8(bin: ...1111111111111111000).It is a valid value (including padding) or not?
PS: i'm investigating a dump that may be a memory corruption so .. can't be sure.PS2: my bool is in class between apointerand asize_t. Compiled as rele... |
It's not a validboolvalue --boolshould only show up as0or1. Since you're seeing 0xf8, the memory is either not initialized or overwritten. (Note that for some reason, WinDbg will only read a single byte and then sign-extend it to 64-bits.)
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:post and pre increment in cUndefined Behavior and Sequence Points
here i want to know why this output comes??
Any one Can Explain me All in proper manner
```
#include<stdio.h>
int main() {
int a=5;
printf("%d %d %d",a++,a++,++a);... |
It's undefined - side effects are only guarantied to be completed atsequence points.
|
I am doing some matrix multiplication in C and I am trying to compile my progam however it fails to compile for the reason:
No such file or directory cblas.h
This is the command I am using to compile:
```
gcc -o BLAS BLAS.c
```
Can anybody please help me? I am compiling this program on a server. I'm not sure if th... |
You need to add a-I directoryoption wheredirectoryis the place where thecblas.hfile is located on your system.
This gives:
```
gcc -o BLAS -I directory_of_cblas_header BLAS.c
```
|
I need to count the length of a string encoded using Huffman compression. It may have '\0' characters sostrlen()or any other function that searches for the NULL terminator won't work. How can I determine the length of such a string?
|
It's not possible. Go on a field and walkuntil the end. There will be nothing different than the rest of the field to mark the end.
Compute the length before encryption (encryption shouldn't typically change it)Use a character that may not appear in the string (if there is one) as terminator
EDIT
The OP mentioned h... |
In Visual Studio 2005, I'm trying to compile a .c file:
```
int i = 6;
int a[i];
```
It doesn't work, so which standard does my compiler follow?
|
Visual Studio only supports C89/90. They have no support for C99. Therefore you cannot use variable-length arrays in Visual Studio. Furthermore, Microsoft has no plans to add support for C99 in their C compiler.
|
When using functions such asscanfyou read bytes from a buffer where (usually) data coming from the keyboard is stored. How is this data stored? Is it stored inside a fixed size vector? Is there any way to access it directly from code?
|
The buffer used by the standard libraries input routines is private to the implementation of the standard library. You cannot access it other than through the published interface to the standard library.
|
I have been implementing a user threads library as part of my assignment.
I didn't understand themakecontextfunction:
```
makecontext(&(mainthread->threadctx),(void(*)(void))start_funct,1,args)
```
What does(void(*)(void))start_functexactly mean? And why do I have to write it this way?
Can't I just write it as
```
... |
void(*)(void)means "pointer to a function that takes no parameters and returnsvoid".
Therefore(void(*)(void))start_functis castingstart_funct(which we can assume is some kind of function pointer)` to the above type. (There is avery useful online toolthat can help you with this until you get more comfortable reading d... |
Why is this legal?
```
extern int foo = 0xF00; // Gets a warning, still compiles
extern void bar() { // No warning
int x;
}
```
Is there a reason to why this is allowed?
|
Sometimes it's useful
```
extern const int foo = 0xF00;
```
Without theextern, in C++foowould bestaticand have internal linkage (which means you could not usefoofrom another translation unit).
Theexternin both cases in your example is redundant.In C99 anexterncan make a difference forinlinefunctions..
|
I am trying to make a mini shell where commands are piped to each other. At some points in the code I do:
```
close(1) //closing stdout
```
and
```
close(0) //closing stdin
```
However later on I am forking so I want my new subprocess to reset everything. So how would I:
```
*function_name_here*(1) //reopening st... |
If you're on a UNIX-type system (and you most likelyareif you're callingfork), you can generally do one of two things.
The first is to open/dev/ttywhich will give you access to your terminal device (assuming the terminal device is what you want rather than the original file handle).
The second is todupthat file hand... |
Now I have some C source codes, I would like to use it in my java application.
I need to execute the C source code, and get back the result to my java application. Instead of re-write all the C source code to java, how can I reuse the C's source code in my java application?
|
Take a look atJava Native Interface.
The Java Native Interface (JNI) is a programming framework that
enables Java code running in a Java Virtual Machine (JVM) to call and
to be called by native applications (programs specific to a
hardware and operating system platform) and libraries written in other
language... |
I have an application that is recording live , the capture file keep growing in size
using fread() and feof() , but feof() is breaking the loop early , so what's the best technique to keep reading from the stream
should I wait and then I can advance the file stream ?should I open the file again and advance to positi... |
I would monitor the file (something likeselect(2)). When notified, I wouldreadas much as possible then wait again.
|
I'm trying to write a function that when given 2 arguments, the 2 leftmost columns, produces the third column as a result:
```
0 0 0
1 0 3
2 0 2
3 0 1
0 1 1
1 1 0
2 1 3
3 1 2
0 2 2
1 2 1
2 2 0
3 2 3
0 3 3
1 3 2
2 3 1
3 3 0
```
I know there will be a modulus involved but I can't quite figure it out.
I'm trying to... |
Ifaandbare the positions of the two persons, their "distance" is:
```
(4+b-a) % 4
```
This also shows that the forth block in your example is wrong.
|
While looking through some example C code, I came across this:
```
y -= m < 3;
```
What does this do? It it some kind of condensed for loop or something? It's impossible to google for as far as I know.
|
m < 3is either1or0, depending on the truth value.
Soy=y-1whenm<3istrue, ory=y-0whenm>=3
|
Is there any way to get the number of keys from an .ini file?
ie.
[mysection]
```
server=192.168.1.100
port=1606
blah1=9090
temp1=abcd
```
etc
I want to get number of key (from the above example it should return 4)
Please, any help will be great.
|
Kernel32.dll exports GetPrivateProfileSection() which returns a null-separated list of name/value pairs. You can count the pairs.
|
In C what is the best way to convert a string in such a format as "293.0000" to the float result 2.93.
By the way is it also possible to remove the decimals with printf and get a result of 293
|
```
char *myNum = "293.0000";
double myDouble = atof(myNum);
int myInt = (int)myDouble;
myDouble /= 100;
printf("double: (%.2f) %f, int: %d\n", myDouble, myDouble, myInt);
```
output:
double: (2.93) 2.930000, int: 293
Note that floating-point types are going to have precision beyond 2 decimal points. When you outpu... |
I tried the following code snippet:
```
void main()
{
int x = 1,y = 1,z = 1;
++x || ++y && ++z;
printf("x = %d\ny = %d\nz = %d\n",x,y,z);
}
```
The output Iexpectedwas:
```
x = 2
y = 2
z = 2
```
But I am getting the output:
```
x = 2
y = 1
z = 1
```
What is the reason for this?
|
This is because of short-circuiting.
http://en.wikipedia.org/wiki/Short-circuit_evaluation
When this is evaluated:
```
++x || ++y && ++z;
```
The first part++xalready determines the value of the entire expression. So the++y && ++zis not executed at all. So the side-effects of++yand++zare not invoked.
|
Inwindows process management, if we want to pass the values of more than oneinheritable handleto a child process, how should it be done.. ? I understand that we can use STARTUPINFO to pass one handle value, but how can I pass multiple handle values to achild process..?
|
The command line is a convenient place to pass all sorts of information.
|
Suppose I create threads withpthreads, is it possible to send them new things to work onafterthey have been initialized, so I don't waste resources in creating new threads? For instance, I create 3 threads, thread 2 signals completion and I send it another "task" without killing it and starting a new one. Thanks.
|
The usual, simple form is an ordinary (work)queue. In principle, you maintain a queue structure, perhaps as a linked list, protected by a mutex. Typically,condition variablesare used by the main/producer threads to notify worker threads that new work is available, so they don't have to poll.
Some previous SO question... |
I want to read a text file line by line, but I'm not interested in the white lines. What nice way is there of skipping the blank lines? I know I could read a line, check if it's blank and free it if it is, and so on until I reach a good line, but I'm wondering if there's some other way to do it.
|
I think your method is good enough. Technically you should even check if it's only spaces :-) Note that if you are usingfscanf(quite used in homework problems), white line skipping is "Included in the price" :-) AND you don't have to fight against "this line is bigger than my buffer, what should I do?"
|
I use gcc-mingw,4.5.2 on Winows 7.
printf of infinity and nan values causes 1.#INF00 and -1.#IND00 to appear in the screen ,instead of infinity && nan
what could be a solution for this problem
UPD:I tried to useisinfandisnanmacros :
```
C3861: 'isinf': identifier not found error
C3861: 'isnan': identifier not foun... |
Use theisinf()andisnan()macros to test wheter a number is an infinite or a NaN.
|
Is it possible in X to create a window that is not visible? I looked at the XCreateSimpleWindow API but did not find any attributes to make it hidden. Is there a way?
Thanks
|
You may be looking for an InputOnly window. You can specify the class as InputOnly when using XCreateWindow.
|
Suppose I create threads withpthreads, is it possible to send them new things to work onafterthey have been initialized, so I don't waste resources in creating new threads? For instance, I create 3 threads, thread 2 signals completion and I send it another "task" without killing it and starting a new one. Thanks.
|
The usual, simple form is an ordinary (work)queue. In principle, you maintain a queue structure, perhaps as a linked list, protected by a mutex. Typically,condition variablesare used by the main/producer threads to notify worker threads that new work is available, so they don't have to poll.
Some previous SO question... |
I want to read a text file line by line, but I'm not interested in the white lines. What nice way is there of skipping the blank lines? I know I could read a line, check if it's blank and free it if it is, and so on until I reach a good line, but I'm wondering if there's some other way to do it.
|
I think your method is good enough. Technically you should even check if it's only spaces :-) Note that if you are usingfscanf(quite used in homework problems), white line skipping is "Included in the price" :-) AND you don't have to fight against "this line is bigger than my buffer, what should I do?"
|
I use gcc-mingw,4.5.2 on Winows 7.
printf of infinity and nan values causes 1.#INF00 and -1.#IND00 to appear in the screen ,instead of infinity && nan
what could be a solution for this problem
UPD:I tried to useisinfandisnanmacros :
```
C3861: 'isinf': identifier not found error
C3861: 'isnan': identifier not foun... |
Use theisinf()andisnan()macros to test wheter a number is an infinite or a NaN.
|
Is it possible in X to create a window that is not visible? I looked at the XCreateSimpleWindow API but did not find any attributes to make it hidden. Is there a way?
Thanks
|
You may be looking for an InputOnly window. You can specify the class as InputOnly when using XCreateWindow.
|
The return data-type of a function,whose prototype is declared in main(), is void.
It cointains an instruction return; as in
```
main()
{
void create(int *p);
*some code*
}
void create(node *list)
{
*some code*
return;
}
```
What will it return,and where will it return??
|
It's not going to return anything, you might have return statements in a void function to kind of alter the flow and exit from the function. ie rather than:
```
void do_something(int i)
{
if (i > 1) {
/* do something */
}
/* otherwise do nothing */
}
```
you might have:
```
void do_something(int i)
{... |
I am still trying to understand about doublepointers.
I do know how double pointers are usually used in most cases like
```
void foo(char **ptr)
{
// blah
}
int main(void)
{
char *ptr;
foo(&ptr);
}
```
However i have no idea what one does differently than the other
```
int main(int argc, char **argv) //D... |
When used as a parameter to a function, an array designator[]is exactly the same as a pointer. The two declarations you have formainare in fact identical.
There are times when the two different syntaxes mean different things, but this isn't one of them.
In this case it means you have an array of pointers. Each point... |
I'm making a program that takes a three-digit integer and splits it into two integers.224would become220and4.114would become110and4.
Basically, you do it with modulos. I wrote what I think should work and the compiler keeps saying that there is a missing parenthesis before the&bigbut any changes just make more errors... |
Take out the "void" in your call to split_num(). It's only used in the function declaration (to signify that it does not return a value), not in actual invocations of it.
|
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed9 years ago.Improve this question
I used inline in every method in my program (implementation of algorithm), does it can make problems?
|
Depends on what your code looks like.
Butnot understanding what your code means? That isdefinitelygoing to cause you problems.
Why don't you try to learn whatinlineactuallydoes, rather than simply whether or not it's going to cause any problems?
The primary effect of theinlinekeyword in C++ is to make the compiler ... |
I need to find a way to determine what files on a shared folder are being accessed, and by whom. Commands like "Net Files" and "Net Session" can give this information, as well as PSFile.exe in SysInternals, but I cannot figure out how to do this programmatically. I have found a way to determine who is accessing a shar... |
You can useADSI(Active Directory Service Interfaces) , some time ago I wrote an article about this topicUsing Delphi and ADSI to enumerate local and remote shared resourcesthe samples are written in delphi but you can use this article as a guide to ADSI.
To List the opened resources like folders and files you must us... |
Say I have libA. It depends on, for example, libSomething for the simple fact that a non-inline method of libA makes a call to a method in libSomething.h. How does the dependency link up in this case? Does libA have to statically link to libSomething when it is compiled, or will a user of libA (an application using li... |
Static linking is just copying the whole items (functions, constants, etc) into the resulting executable. If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.
This... |
Questions likethisandthisshow you how to send an HTTP POST request using Cocoa and objective-c.
Is there any way to use that code in C? Furthermore, how to send an HTTPS (SSL) POST request using C on Mac OS X?
Thanks for the help
EDIT:
IF you don't like the fact that I am asking this question please stay away, do ... |
Core Foundation is C, and includes very nice HTTP support:
Communicating with HTTP Servers
The snippet is for GET, but POST is supported and straightforward. Here's a snippet that does use POST. Core Foundation is fully supported, 64-bit, iOS, an essential Mac OS and iOS API.
An answer to a JSON question
|
I have downloaded the timezone database library and am trying to compile it under windows to a DLL. When I do this, I get messages like:
```
1>c:\javatools\tzinfo\src\private.h(97): fatal error C1083: Cannot open include file: 'sys/wait.h': No such file or directory
```
and, of course, sys/wait.h is not ANSI C, whic... |
fork(),wait()andwaitpid()are defined by the POSIX standard, and Windows is not POSIX-compliant.
In order to have POSIX compliance under Windows, you should compile under Cygwin.
The analogous WinAPI functions areCreateProcessandGetProcessExitCode.
|
i have to useexit(1)command in a function.
Does it have anything to do with the return data type of the function in which it is being used?
|
No. Theexitfunction never returns but instead terminates the process it's called from. The C compiler has no intuitive understanding of it and treats it like any othervoidreturning function.
This does mean though that whileexitwill end your function the C compiler doesn't see it that way. Hence it will still want ... |
I'm following this basic example how to create a system driver:
http://sriramk.com/blog/2007/09/world-windows-driver-from-scratch.html
When I do the build I get the following (above the BUILD: lines):
```
0>XmlLog::File::CopyXslFile(): Unable to copy the XML style sheet C:\WinDDK\\7600.16385.1\\bin\\x86\\build.xsl ... |
Try usingVisualDDK. It integrates nicely with VS2k10 and alleviates all the burdens regarding building of a device driver.
|
In a nutshell I typically build a MySQL query within C using sprintf
i.e.
```
sprintf(sqlcmd,"update foo set dog=\"lab\" where description=\"%s\"",some_desc);
mysql_query(some_conn,sqlcmd);
```
However if some_desc is something likeCrazy 5" Dog, then MySql Server screams, as it's confused over the dangling quote.
... |
Although MySQL has amysql_real_escape_string()function, you should probably be usingprepared statementsinstead, which allow you to use ? placeholders instead of real parameters, and then bind them to the real parameters before each execution of the statement.
|
When I compile my code I am getting a unknown Opcode '.pword' error. The only line of code in my project that has .pword is:
```
do {
__asm__ volatile (" .pword 0xDA4000");
Nop();
} while(0)
```
Commenting the line out does nothing.
I searched.pword 0xDA4000and know it is supported by the IDE MPLab for PIC... |
In MPLAB ASM30 assembler the.pworddeclare 24 bit constant in code memory. It can be also any MPLAB ASM30 instruction.
Check:MPLAB ASM30 assembler
|
getpwnam_r() is reentrant according a number of manpages. However, thestandardonly state
The getpwnam_r() function is thread-safe and returns values in a user-supplied buffer instead of possibly using a static data area that may be overwritten by each call.
I am confused. Must a NSS Module's ...getpwnam_r() function... |
Well, as you note the standard requires that the function must be thread-safe. That doesn't prevent an implementation from providing a stricter guarantee.
IOW, portable software cannot assume that getpwnam_r is reentrant. But, if you care only about some specific platform which guarantees that it's reentrant, then pr... |
What C/C++ Libraries are there for detecting the multi-byte character encoding (UTF-8, UTF-16, etc) of character array (char*). A bonus would be to also detect when the matcher halted, that is detectprefixmatch ranges of a given set of a possible encodings.
|
ICU doescharacter set detection. You must note that, as the ICU documentation states:
This is, at best, an imprecise operation using statistics and
heuristics. Because of this, detection works best if you supply at
least a few hundred bytes of character data that's mostly in a single
language.
|
In my program I haveuint4 xvariable.
I have to print its value to stdout.
How can I implement it usingprintf?
Thank you in advance
Note:uint4 xa structure of 4 unsigned integers
|
uint4is no standard type and there's no common definition. I know of projects whereuint4refers to any of these:
a 32-bit unsigned integer type (1)a 4-bit unsigned integer type, realized as a bitfield (2)a structure of 4 unsigned integers (3)
You'd print them like this:
```
// case (1)
#include <inttypes.h>
typedef... |
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago.
ok guys,
this is a very good questi... |
This is not possible. The best you could do is write a macro (shudder) that passes the type and name as arguments to the function without you having to write them a second time.
|
How can I extract 2 bytes or any amount of bytes from xmm register?
Currently I am using an array to dump the whole register and then I access the bytes that I want. However that seems not as efficient as it could be. Is there a way to efficiently get just the bytes I am interested in?
(I am working in C on Linux 64... |
The mnemonics for the instructions you probably want areMOVDandMOVQand corresponding intrinsics are_mm_cvtsi128_si32and_mm_cvtsi128_si64.
|
I have the following code:
```
char *array1[3] =
{
"hello",
"world",
"there."
};
struct locator_t
{
char **t;
int len;
} locator[2] =
{
{
array1,
10
}
};
```
It compiles OK with "gcc -Wall -ansi -pedantic". But with another toolchain (Rowley), it complains about
```
war... |
Seems perfectly legal to me;char *[3]decays tochar **, so the assignment should be valid.
Neither GCC 4.4.5 nor CLang 1.1 complains.
|
see if i write in any c file like
```
#include "header.h"
```
then it will search this file in current directory
but when i write
```
#include <header.h>
```
then where it will go to find this file ?
what is defualt path for header file included in c program?
see i have installed gstreamer in /usr/local but whe... |
Try runninggcc -v -E -. When I do, part of the output is as follows:
```
#include <...> search starts here:
/usr/lib/gcc/i686-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
/usr/include/i386-linux-gnu
/usr/include
```
It's not an answer to the gstreamer question, but... |
I need to make a binary plugin in C that works with both Firefox and Chromium, on Linux. Where can I find a simple example of an NPAPI plugin for Linux, written in C?
|
Use FireBreath the cross platform/cross browser plugin projecthttp://firebreath.org
|
I am currently having to write implementations of malloc() and free(), and am given a driver program that will run my two implementations.
But currently, I am segfaulting because free() is trying to free a payload size that is well in the billions of bytes (which is wrong). I have the line and line number from runnin... |
First set a breakpoint for malloc and free. Afterwards use the "ignore" command with a high value to suppress really stopping at those breakpoints. GDB will still count how many times the breakpoints have been hit. When you call "info breakpoints", GDB will show you these counts.
|
I can't prepare this statement in my Pro*C code. When I running this statement I get this error:
```
SQLERROR: ORA CODE: -900 MSG: ORA-00900: invalid SQL statement
```
Is there a way to exec this statement with EXEC SQL?
|
No, you can't do that because describe is a SQL*Plus command (under the covers it queries the data dictionary).
If you need to actually describe a table, in order to programmatically interpret columns and datatypes of a columns, you'll need to do dynamic SQL method 4.
See this link for a good description:http://down... |
I Have a struct that is set up like so:
```
struct formula {
NSString *FormulaName;
NSString *FormulaContent;
};
```
That piece of code is in my AppDelegate Header.
Now, In my AppDelegate implementation.
```
struct formula AreaOfSquare;
AreaOfSquare.FormulaName = @"Area Of a Square";
AreaOfSquare.FormulaCo... |
If you have references to your Interface Builder objects in a view controller, i.e.
```
IBOutlet UILabel* titleLabel;
```
you could just set its text directly in code:
```
titleLabel.text= AreaOfSquare.FormulaName;
```
|
I have written a FUSE driver for linux, and when I mount it I get an entry in the nautilus sidebar. I do not want this - the unmount button doesnt even work. I would like to hide this entry in the nautilus sidebar for my mounted fuse filesystem. I dont want to add it to the fstab because running it as root opens secur... |
I believe Nautilus will only show those sidebar entries if your mount point is under/media(the designated path for "removable media" under theFHS).
Using a mount point under/mntshould make Nautilus ignore the filesystem.
|
I am writing a function that takes a OpenCV Mat structure and does some processing. The problem is that OpenCV doesn't seem to have a type independent way for accessing the strucutre so I have to do something like this.
```
int myfunc(cv::Mat& im, int iRow, int iCol)
{
int iResult = 0;
if (im.type()==CV_16U)... |
It's because you generally require high performance in image processing and so need different algorithms for 8bit, 16bit or double image types.
You can do it all with templated types but that's often just a less readable way of having a switch statement.
ps if you do care about performance you shouldn't be using the... |
When I compile my code I am getting a unknown Opcode '.pword' error. The only line of code in my project that has .pword is:
```
do {
__asm__ volatile (" .pword 0xDA4000");
Nop();
} while(0)
```
Commenting the line out does nothing.
I searched.pword 0xDA4000and know it is supported by the IDE MPLab for PIC... |
In MPLAB ASM30 assembler the.pworddeclare 24 bit constant in code memory. It can be also any MPLAB ASM30 instruction.
Check:MPLAB ASM30 assembler
|
getpwnam_r() is reentrant according a number of manpages. However, thestandardonly state
The getpwnam_r() function is thread-safe and returns values in a user-supplied buffer instead of possibly using a static data area that may be overwritten by each call.
I am confused. Must a NSS Module's ...getpwnam_r() function... |
Well, as you note the standard requires that the function must be thread-safe. That doesn't prevent an implementation from providing a stricter guarantee.
IOW, portable software cannot assume that getpwnam_r is reentrant. But, if you care only about some specific platform which guarantees that it's reentrant, then pr... |
What C/C++ Libraries are there for detecting the multi-byte character encoding (UTF-8, UTF-16, etc) of character array (char*). A bonus would be to also detect when the matcher halted, that is detectprefixmatch ranges of a given set of a possible encodings.
|
ICU doescharacter set detection. You must note that, as the ICU documentation states:
This is, at best, an imprecise operation using statistics and
heuristics. Because of this, detection works best if you supply at
least a few hundred bytes of character data that's mostly in a single
language.
|
In my program I haveuint4 xvariable.
I have to print its value to stdout.
How can I implement it usingprintf?
Thank you in advance
Note:uint4 xa structure of 4 unsigned integers
|
uint4is no standard type and there's no common definition. I know of projects whereuint4refers to any of these:
a 32-bit unsigned integer type (1)a 4-bit unsigned integer type, realized as a bitfield (2)a structure of 4 unsigned integers (3)
You'd print them like this:
```
// case (1)
#include <inttypes.h>
typedef... |
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago.
ok guys,
this is a very good questi... |
This is not possible. The best you could do is write a macro (shudder) that passes the type and name as arguments to the function without you having to write them a second time.
|
How can I extract 2 bytes or any amount of bytes from xmm register?
Currently I am using an array to dump the whole register and then I access the bytes that I want. However that seems not as efficient as it could be. Is there a way to efficiently get just the bytes I am interested in?
(I am working in C on Linux 64... |
The mnemonics for the instructions you probably want areMOVDandMOVQand corresponding intrinsics are_mm_cvtsi128_si32and_mm_cvtsi128_si64.
|
I have the following code:
```
char *array1[3] =
{
"hello",
"world",
"there."
};
struct locator_t
{
char **t;
int len;
} locator[2] =
{
{
array1,
10
}
};
```
It compiles OK with "gcc -Wall -ansi -pedantic". But with another toolchain (Rowley), it complains about
```
war... |
Seems perfectly legal to me;char *[3]decays tochar **, so the assignment should be valid.
Neither GCC 4.4.5 nor CLang 1.1 complains.
|
see if i write in any c file like
```
#include "header.h"
```
then it will search this file in current directory
but when i write
```
#include <header.h>
```
then where it will go to find this file ?
what is defualt path for header file included in c program?
see i have installed gstreamer in /usr/local but whe... |
Try runninggcc -v -E -. When I do, part of the output is as follows:
```
#include <...> search starts here:
/usr/lib/gcc/i686-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
/usr/include/i386-linux-gnu
/usr/include
```
It's not an answer to the gstreamer question, but... |
I need to make a binary plugin in C that works with both Firefox and Chromium, on Linux. Where can I find a simple example of an NPAPI plugin for Linux, written in C?
|
Use FireBreath the cross platform/cross browser plugin projecthttp://firebreath.org
|
I am currently having to write implementations of malloc() and free(), and am given a driver program that will run my two implementations.
But currently, I am segfaulting because free() is trying to free a payload size that is well in the billions of bytes (which is wrong). I have the line and line number from runnin... |
First set a breakpoint for malloc and free. Afterwards use the "ignore" command with a high value to suppress really stopping at those breakpoints. GDB will still count how many times the breakpoints have been hit. When you call "info breakpoints", GDB will show you these counts.
|
I can't prepare this statement in my Pro*C code. When I running this statement I get this error:
```
SQLERROR: ORA CODE: -900 MSG: ORA-00900: invalid SQL statement
```
Is there a way to exec this statement with EXEC SQL?
|
No, you can't do that because describe is a SQL*Plus command (under the covers it queries the data dictionary).
If you need to actually describe a table, in order to programmatically interpret columns and datatypes of a columns, you'll need to do dynamic SQL method 4.
See this link for a good description:http://down... |
I Have a struct that is set up like so:
```
struct formula {
NSString *FormulaName;
NSString *FormulaContent;
};
```
That piece of code is in my AppDelegate Header.
Now, In my AppDelegate implementation.
```
struct formula AreaOfSquare;
AreaOfSquare.FormulaName = @"Area Of a Square";
AreaOfSquare.FormulaCo... |
If you have references to your Interface Builder objects in a view controller, i.e.
```
IBOutlet UILabel* titleLabel;
```
you could just set its text directly in code:
```
titleLabel.text= AreaOfSquare.FormulaName;
```
|
I have written a FUSE driver for linux, and when I mount it I get an entry in the nautilus sidebar. I do not want this - the unmount button doesnt even work. I would like to hide this entry in the nautilus sidebar for my mounted fuse filesystem. I dont want to add it to the fstab because running it as root opens secur... |
I believe Nautilus will only show those sidebar entries if your mount point is under/media(the designated path for "removable media" under theFHS).
Using a mount point under/mntshould make Nautilus ignore the filesystem.
|
I am writing a function that takes a OpenCV Mat structure and does some processing. The problem is that OpenCV doesn't seem to have a type independent way for accessing the strucutre so I have to do something like this.
```
int myfunc(cv::Mat& im, int iRow, int iCol)
{
int iResult = 0;
if (im.type()==CV_16U)... |
It's because you generally require high performance in image processing and so need different algorithms for 8bit, 16bit or double image types.
You can do it all with templated types but that's often just a less readable way of having a switch statement.
ps if you do care about performance you shouldn't be using the... |
_vscprintfis not available on Android. Alsovsprintf(NULL, fmt, ap)does not work (produces seg fault), so there seems to be no way of calculating size of buffer required for vsnprintf to succeed?
Androidsourcesindicate that__android_log_printfunction just truncates strings to 1024 using vsnprintf...
How do you handle... |
Section [7.19.6.13]—Thevsprintffunction—of the C99 Standard does not state that the output buffer may beNULL.
You probably want to usevsnprintf:
```
int len = vsnprintf(NULL, 0, fmt, ap)
```
If the call is successful, the return value is the number of characters that would have been written if the buffer were large... |
I'm implementing a function in C where I convert a byte[] to an int[]. The problem is that the length of the int[] depends on the contents of the byte[] (not just the length of the byte[]) so I won't know the total length of the int[] until I've iterated the entire byte[]. I'm therefore looking for some form av int-st... |
The easiest method would be to allocate theint[]to be the same length (number of elements) as thebyte[], and when you're done and know the size, callreallocto shrink it.
This assumes, of course, that interpreting the data would never createmoreintegers than there are bytes in the stream.
|
I'd like to know in the code (.c file) how I can find the linux distribution name version (like ubuntu 10.0.4, or centOS 5.5...)?
The c function that I'm looking for should be like the uname() system call used in (.c files) to get kernel version.
it will be appreciated that the function is working for all linux distri... |
There is no standard for this yet. You can query following files or check for existence:
```
/etc/lsb-release
/etc/issue
/etc/*release
/etc/*version
```
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago.
How to take some unknown number of ... |
Well the prototype for main is:
main(void) or
main(int argc, char *argv[]);
This are the command line arguments of the program
you can iterate through them with something along this lines
```
int i = 0;
for (i=0; i < argc; i++) {
printf("%s" argv[i]);
}
```
Untested but should be enough to get you goi... |
On a sftp server i create a "lockfile.lock" if another application is manipulating data.
No in my c application i would like to check if the lockfile.lock exists and than "WAIT 5 SECONDS".
How do i wait 5 seconds in c without blasting the CPU to 100%?
Thanks
|
On windows and linux there is a system call "sleep()".Windows,Linux
|
I have the following on AIX 6.1:
```
#include <stdio.h>
#include <stdlib.h>
int main(){
#if defined(__AIX)
printf("hello world");
#endif
return 0;
}
```
I have followed the instructions fromhttp://predef.sourceforge.net/preos.html#sec2but am scratching my head as to why it does not work or print out "hello worl... |
should be 1 underscore not 2 underscores before "AIX"....solved now ;-)
|
When you exit the program, how do theseFILE*objects get closed and released?
|
They are closed by the C runtime code which is automatically linked to your program - the code that calls your main() function also calls exit() after main() returns.
|
Is there a method of quickly determining whether a (4KB-16MB) chunk read from a file is all zeros?
You can iterate over the chunk, checking each byte. There are obvious optimisations, but it remains O(N).
My use case is for sparse files. I would be perfectly happy for a partial solution, such that if the chunk I'v... |
This depends on the operating system and sometimes the filesystem. Linux since 2.6.28 has implemented theFIEMAPioctl(), and ZFS on Solaris implementsSEEK_HOLEandSEEK_DATAinlseek().
|
We have installed GCC and libgcc on AIX.
I am busy compiling a C library on the machine and keep getting the following error:
Undefined symbol: .main
Any idea how to solve this?
Thanks for the help
Lynton
|
You are most likely using the wrong gcc arguments - probably you are using the same ones you'd use for an executable program (wheremain()is required). The correct arguments depend on what kind of library you want to build (a static one or a dynamic (.so) one)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.