question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
How do you initialize special ASCII chars, for example EOT (0x04), ENQ(0x05)?
```
char CHAR1 = '\EOT';
char CHAR2 = '\ENQ';
```
Is this correct?
| You can put character code into the variable:
```
char CHAR1 = 4;
char CHAR2 = 5;
```
You can also use escape sequences which you'll findhere.
|
I saw this code inthis .c file.
```
struct node {
Item data;
struct node *next;
};
struct stack_type {
struct node *top;
};
```
What are the benefits of creating two structs when one would do?
| It may make the code clearer to distinguish between the whole stack and a single node.
|
We have
```
int main(int argc, char** argv, char** envc)
```
for the ordinary. but I want to know if there is any other argument main can have instead of these. And if there is any, what does it point to?
| Well, heres the breakdown:
argc-- C standardargv-- C standardenv-- Works on most UNIX and MS Win, but not standardapple-- Other information passed as forth argument by Mac OSX and Darwin
|
Suppose a program has memory leaks.
1) When a process dies (normally or segmentation fault), are those leaked memory freed?
2) What aboutother resourcesa process holds?
| With most modern operating systems (linux, windows from around NT 3.5), yes.
|
How do you initialize special ASCII chars, for example EOT (0x04), ENQ(0x05)?
```
char CHAR1 = '\EOT';
char CHAR2 = '\ENQ';
```
Is this correct?
| You can put character code into the variable:
```
char CHAR1 = 4;
char CHAR2 = 5;
```
You can also use escape sequences which you'll findhere.
|
Suppose a program has memory leaks.
1) When a process dies (normally or segmentation fault), are those leaked memory freed?
2) What aboutother resourcesa process holds?
| With most modern operating systems (linux, windows from around NT 3.5), yes.
|
How do you initialize special ASCII chars, for example EOT (0x04), ENQ(0x05)?
```
char CHAR1 = '\EOT';
char CHAR2 = '\ENQ';
```
Is this correct?
| You can put character code into the variable:
```
char CHAR1 = 4;
char CHAR2 = 5;
```
You can also use escape sequences which you'll findhere.
|
Saw this in an answer to another question:
```
char (*arrs)[rowSize] = malloc(bytesPerTable);
```
What is arrs? / why are there parentheses / what is the description of this declaration?
| What is arrs ? what is the description of this declaration?
It's a pointer to an array ofrowSizechars, vastly different from a pointer to achar.
why are there parentheses
Because without them it would be an array of pointers tochar.
|
When I do something like:
```
./foo -uxw --bar something
```
Does the shell automatically parse these commands, or does each program have to do the parsing itself?
| Each program parses its arguments. You'll probably want to look intogetoptfor that so the answer becomes:each program usually relies ongetoptto parse arguments.
|
Here's what I have:
```
#define STRING "string 1"
string string2 = STRING + "string3";
```
This is wrong. What is the solution? Is the problem thatstring2must be constant or what else, and why?
| ```
#define STRING "string 1"
std::string string2 = STRING "string3";
```
Concatenation of adjacent string litterals isn't a feature of the preprocessor, it is a feature of the C/C++
|
I have a C program.
```
int main ()
{
if (getchar()!=EOF)
puts("Got a character");
else
puts("EOF");
}
```
What should I type into the stdin on the terminal to produce an EOF?
| In Windows,Control+Zis the typical keyboard shortcut to mean "end of file", in Linux and Unix it's typicallyControl+D.
|
Do I just usefree()function to free the pointer, or some specific API?
| Sincereadahead()populates the page cache, memory is handled by the kernel. You don't do anything.
|
How do I initialize a new line char in C?
For example, to initialize char A:
```
char letter = 'A';
```
How to initialize new line? Like this maybe:
```
char newLine = '0x0A'?
```
| Use an escape character like this:
```
char letter = '\n';
```
|
Do I just usefree()function to free the pointer, or some specific API?
| Sincereadahead()populates the page cache, memory is handled by the kernel. You don't do anything.
|
How do I initialize a new line char in C?
For example, to initialize char A:
```
char letter = 'A';
```
How to initialize new line? Like this maybe:
```
char newLine = '0x0A'?
```
| Use an escape character like this:
```
char letter = '\n';
```
|
Is there a way to dynamically load compiled c-code in a linux-kernel-module at run-time?
I am looking for something likedlopenfromlibdl.
| Yes. Move the code into another modules and then create a dependency to that other module in yours.
|
```
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
__be32 daddr, __be16 dport, int dif)
```
Here is declaration of function, that converts connection attributes tostruct sock.
As I googled, first argument should be&init_net. But what should be last argument?
| Thedifargument is the device interface.
|
There must be something I'm misunderstanding, why does this not return 10?
```
int main() {
float i = 0;
func(i);
printf("%f", i);
return 0;
}
void func(float i) {
int j;
for (j = 0; j < 5; j++) {
i += 2;
}
}
```
| Primitive types (like floats) are "passed by value", func() is really modifying a copy of i.
|
Does autotools comes out of box for all the major unix systems? I am looking for something that can compile the code without installing any additional software and platform independent(UNIX flavors and Architecture).
| If you use autotools correctly, the end result is a scriptconfigureso that
```
configure
make
make install
```
works -- and yes, the very point of autotools is that this should work just about everywhere.
|
I'm dealing with win32 api subclass. My issue is I don't know my subclass procedure is running on a dialog or a "normal window". Can anyone tell me how can I determine current window is a dialog or a normal window?
| Check the name of the window class. There is no formal documented way of determining this other than that.
|
Is there a way to dynamically load compiled c-code in a linux-kernel-module at run-time?
I am looking for something likedlopenfromlibdl.
| Yes. Move the code into another modules and then create a dependency to that other module in yours.
|
```
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
__be32 daddr, __be16 dport, int dif)
```
Here is declaration of function, that converts connection attributes tostruct sock.
As I googled, first argument should be&init_net. But what should be last argument?
| Thedifargument is the device interface.
|
There must be something I'm misunderstanding, why does this not return 10?
```
int main() {
float i = 0;
func(i);
printf("%f", i);
return 0;
}
void func(float i) {
int j;
for (j = 0; j < 5; j++) {
i += 2;
}
}
```
| Primitive types (like floats) are "passed by value", func() is really modifying a copy of i.
|
How can I get the PID of the user process which triggered my Kernel module'sfile_operation.readroutine (i.e., which process is reading/dev/mydev) ?
| When your read function is executing, it's doing so in the context of the process that issued the system call. You should thus pe able to usecurrent, i.e.current->pid.
|
Is it possible to do these things from a nativeCorC++-compiled program (gcc):
Callclangand compile givenCcode of a function, passed asconst char *.Obtain a pointer and run it in the LLVM virtual machine.Acquire the result in the native program and continue.
How?
| For a minimalistic example, seeClang interpreter.
Clingis bit more practical example of such an approach.
|
How does the initialization happen in cases 2, 3, 4, 5 below. 1 will contain garbage.
```
char x[16];
char x[16] = {0};
char x[16] = {0, };
char x[16] = {1};
char x[16] = {1, };
```
| If you use the brace initializer syntax with arrays, any additional elements not mentioned in the initializer list are initialized with zeros.
|
I have to create an array of char pointers each of them of size 10000000 using the best and optimized way to do this in C.
| I think this will do (haven't checked for nulls though):
```
int i;
int num_arrays;
char **huge_char_array;
num_arrays = 10; //number of arrays you want.
huge_char_array = (char **)malloc(sizeof(char *) * num_arrays);
for(i = 0; i < num_arrays; i++)
{
huge_char_array[i] = (char *)malloc(sizeof(char) * 10000000);
}
```
|
May be it is one of the simplest things for C programmers but I really can't get it.
```
unsigned char Value[4];
unsigned long ulVer = 00010001;
unsigned long uSize = sizeof(ulVer);
memcpy(Value, &ulVer, uSize);
memcpy(&ulVer, Value, uSize);
printf("%d",ulVer);
```
Why ulVer is 4097, not 10001 ?
| 00010001; is an octal constant because it starts with 0.
You need to write 10001 if that's what you want in decimal.
|
May be it is one of the simplest things for C programmers but I really can't get it.
```
unsigned char Value[4];
unsigned long ulVer = 00010001;
unsigned long uSize = sizeof(ulVer);
memcpy(Value, &ulVer, uSize);
memcpy(&ulVer, Value, uSize);
printf("%d",ulVer);
```
Why ulVer is 4097, not 10001 ?
| 00010001; is an octal constant because it starts with 0.
You need to write 10001 if that's what you want in decimal.
|
This is just a quick question. As I understand it, code from a static library is included directly, at compile time, into a .exe... so if I have some Library code running in a program, is it correct to say that the current directory as far as that code is concerned is the same as that of the .exe's, regardless of where the .lib is?
| It doesn't matter where the lib is, even if it is dynamically linked.
|
In some C-source file I've seen comments in the format:
```
/**
* @bla bla bla
* bla bla..
*/
```
Someone told me that if I comment my.c/.hfiles properly, then with a certain tool I can autogenerate man pages from those files automatically.
Does anybody know if this is possible? (How to do, which software should I use, etc.)
| It looks like you are searching fordoxygen
|
dois a keyword in C and all I have seen is that it is only used withwhile. So my question is candobe used alone withoutwhile.
If yes how?
| No. It cannot.
To be more precise, this is what theC standardhas to say:
6.8.5 Iteration statementsSyntaxiteration-statement:while ( expression ) statementdo statement while ( expression ) ;for ( expressionopt ; expressionopt ; expressionopt ) statementfor ( declaration expressionopt ; expressionopt ) statement
|
should we useperrorinside signal handler because they have a user space buffer likeprintfand other stdio functions?
| perroris not listed in the table of async-signal-safe functions (e.g.,section 2.4.3 Signal Actions) so it is not safe to call from a signal handler that may be invoked in response to a signal interrupting a non-async-signal-safe function.
|
How do I printf integers? When I use:
```
int n = GetInt();
printf("%n \n", n);
```
I get the error that there was an unused variable and I can't compile it.
| A signed integer uses%d(or%i).
See alsoman 3 printf(on Unix-like systems) for the whole list of modifiers.
|
For example, in a linux-machine there are so many process.
Each one is able to use a syscall, but usually few are used.
Well, there is a tool or a manner to show when a syscall is used and which is the process associated?
| You can use various tools, likestrace,ltraceand many other, although I'm not sure you want to trace all processes at the same time.
Normally you'd attach to one process of interest and follow its system calls.
|
I would like to declare an array in kernel module and to access it within a userspace app. how can I do it?
How do I memory map it for using via userspace so it can be used by a user?
| You will most likely need to implement a character device. Then in your instance ofstruct file_operationsimplement themmap function.
|
Following is line of code in c.
```
i++=i++;
```
Output:Error Lvalue required.So what does this error indicate?
| The result ofi++is not a lvalue and the standard requires the left operand of the assignment operator to be a lvalue.
Even if it was allowed your program would invoke undefined behavior as you are trying to modify the same object twice between two sequence points.
|
For example, in a linux-machine there are so many process.
Each one is able to use a syscall, but usually few are used.
Well, there is a tool or a manner to show when a syscall is used and which is the process associated?
| You can use various tools, likestrace,ltraceand many other, although I'm not sure you want to trace all processes at the same time.
Normally you'd attach to one process of interest and follow its system calls.
|
I would like to declare an array in kernel module and to access it within a userspace app. how can I do it?
How do I memory map it for using via userspace so it can be used by a user?
| You will most likely need to implement a character device. Then in your instance ofstruct file_operationsimplement themmap function.
|
Following is line of code in c.
```
i++=i++;
```
Output:Error Lvalue required.So what does this error indicate?
| The result ofi++is not a lvalue and the standard requires the left operand of the assignment operator to be a lvalue.
Even if it was allowed your program would invoke undefined behavior as you are trying to modify the same object twice between two sequence points.
|
There is a way to monitor directories for changes like FileSystemWatcher but in C?
NOTE: I (have to) use gcc.
| SeeFindFirstChangeNotificationorReadDirectoryChangesW.
|
There is a way to monitor directories for changes like FileSystemWatcher but in C?
NOTE: I (have to) use gcc.
| SeeFindFirstChangeNotificationorReadDirectoryChangesW.
|
I would like to create a group in Windows, and I've found the next reference but I don't know if I'm on the right path:
http://msdn.microsoft.com/en-us/library/aa374177.aspx
| No. The right way is using aNet* functions family.In your case to create a new windows user group you have to use aNetGroupAddfunction.
|
Can someone please explain why I should use strstr or string find() ? Which one is faster, at where ?
| In C++ you should use std::string::find(), in C you should use strstr(). The difference in performance should not be significant.
|
```
#include<stdio.h>
int main()
{
int i;
string A[]={"Ahmet", "Mehmet", "Bulent", "Fuat"};
for(i=0;i<=3;i++){
printf("%s",A[i]);
}
return 0;
}
```
How can i see my array's elements as output?
Compiler says "'string' undeclared".
| This way:
```
char *A[] = {"Ahmet", "Mehmet", "Bülent", "Fuat"};
```
Ais an array of pointers tochar.
|
In C/C++
How can I read from serial port, without removing the info I have already read from the buffer?
I want to do something like the Peek function of arduino (http://arduino.cc/en/Serial/Peek) in a linux machine.
| The serial port is accessed as though it is a file using a file descriptor so afgetc ungetcmethod should work.
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:C -> sizeof string is always 8
If I dosizeof("HELLO");I get 6, which is expected, however if I have:
```
void printLength(char *s) {
sizeof(s);
}
```
When passing "Hello" to to this functionsizeofreturns 8.
Why is this?
| What you are getting is size ofchar *. To get it's actual length, usestrlen.
|
I am compiling code withclangwith -O4 optimization. However, I want to disable inlining of functions. I have my own LLVM pass that injects some code to the generated code. After my pass, I want to enable the inlining of functions. How can I do that.
| You can use opt whichsaysit can run passes in any order.
```
clang -c main.cpp -O0 -emit-llvm | opt -load yourplugin -yourpass -inline
```
|
I have fixed an error in my code, but every time I callndk-buildthe same error is STILL there. I have calledndk-build cleanfifteen times at least, but I have had no luck. I have gone into my project and deleted my.o files. What should I do?
Notice the spelling ofinitilized/initialized:
| In Eclipse, menuWindow->project->Clean.
|
Could someone help me by telling what is the Visual C equivalent of fseeko, fseeko64; ftello, ftello64?
Thanks :)
| There are no functions that returns/use off_t, if you need a 64bit position you can use:
_fseeki64
_ftelli64
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:C -> sizeof string is always 8
If I dosizeof("HELLO");I get 6, which is expected, however if I have:
```
void printLength(char *s) {
sizeof(s);
}
```
When passing "Hello" to to this functionsizeofreturns 8.
Why is this?
| What you are getting is size ofchar *. To get it's actual length, usestrlen.
|
I am compiling code withclangwith -O4 optimization. However, I want to disable inlining of functions. I have my own LLVM pass that injects some code to the generated code. After my pass, I want to enable the inlining of functions. How can I do that.
| You can use opt whichsaysit can run passes in any order.
```
clang -c main.cpp -O0 -emit-llvm | opt -load yourplugin -yourpass -inline
```
|
I have fixed an error in my code, but every time I callndk-buildthe same error is STILL there. I have calledndk-build cleanfifteen times at least, but I have had no luck. I have gone into my project and deleted my.o files. What should I do?
Notice the spelling ofinitilized/initialized:
| In Eclipse, menuWindow->project->Clean.
|
Could someone help me by telling what is the Visual C equivalent of fseeko, fseeko64; ftello, ftello64?
Thanks :)
| There are no functions that returns/use off_t, if you need a 64bit position you can use:
_fseeki64
_ftelli64
|
I have a C program which contains#include <dos.h>header. It shows a compile time error. I know that thedos.hheader file is not valid in Linux.
Is there any other equivalent header fordos.hin Linux?
| dos.h header file is interface to the DOS operating system. They are not portable to operating systems other than DOS (means not works in Linux). Which functionality in dos.h you are going to use?
|
Is there a canonical way to check the size of a file in Windows? Googling brings me bothFindFirstFileandGetFileSizeExbut no clear winner. And must GetLastError always be called too?
| If you just want the size, theGetFileSizeExis the clear winner. Yes,FindFirstFilewill do the job too, but it's really intended for other purposes, and unless you need to do those other things, its use is likely to mislead or confuse the reader.
|
Is there a canonical way to check the size of a file in Windows? Googling brings me bothFindFirstFileandGetFileSizeExbut no clear winner. And must GetLastError always be called too?
| If you just want the size, theGetFileSizeExis the clear winner. Yes,FindFirstFilewill do the job too, but it's really intended for other purposes, and unless you need to do those other things, its use is likely to mislead or confuse the reader.
|
In C, when is it preferrable to use one over the other?
| It is really a matter of style and of coding conventions, since in Cp[i]isdefinedto be the same as*(p+i)wherepis a pointer andian integral index. AFAIK you could even writei[p]but that is ugly.
This is not always true in C++ (which gives you the power of definingoperator []etc...).
I personally dislike hand-coding&p[i]and preferp+iin that case.
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:how to printf uint64_t?
I want to printu_int64_tin C.
I want to know the format specifier for this?
I am a C user, I want to do aprintf().
| ```
#include <inttypes.h>
#include <stdio.h>
uint64_t t = 42;
printf("%" PRIu64 "\n", t);
```
|
I try to use CFLocaleCopyCurrent under OSX 10.5.8 but I get weird error:
```
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, char **argv){
setlocale(LC_ALL, "");
CFLocaleRef loc = CFLocaleCopyCurrent();
return 0;
}
Undefined symbols:
"_CFLocaleCopyCurrent", referenced from: _main in ccn51XwH.o
```
| try/usr/bin/gcc -framework Foundation test.c
|
I want to share memory between two processes. One way I know is tommapa shared file. However, I don't want to use a shared file, I want an anonymous mapping in the memory. How can I do that.
| shm_openis your friend. You can unmap the shared region by usingshm_unlink.
|
I try to use CFLocaleCopyCurrent under OSX 10.5.8 but I get weird error:
```
#include <CoreFoundation/CoreFoundation.h>
int main(int argc, char **argv){
setlocale(LC_ALL, "");
CFLocaleRef loc = CFLocaleCopyCurrent();
return 0;
}
Undefined symbols:
"_CFLocaleCopyCurrent", referenced from: _main in ccn51XwH.o
```
| try/usr/bin/gcc -framework Foundation test.c
|
I want to share memory between two processes. One way I know is tommapa shared file. However, I don't want to use a shared file, I want an anonymous mapping in the memory. How can I do that.
| shm_openis your friend. You can unmap the shared region by usingshm_unlink.
|
```
#include<stdio.h>
int main(){
char a[3];
char *b=NULL;
a[0]=0;
a[1]=1;
a[2]=2;
b = a;
printf("%c",b);
b++;
printf("%c",b);
b++;
printf("%c",b);
return 0;
}
```
I tried to print the values 0,1,2 by incrementing the pointer by 1. please help
| b is a pointer in itself, you have to dereference it to get the actual values:
```
printf("%d", *b);
b++;
printf("%d", *b);
b++;
```
etc.
|
Anybody knows where is a list of the AVERROR meanings? Something like
```
-1: reason A
-2: reason B
```
and so forth?
| You can useav_strerror()to get a string representation of the error code.
If you simply want to look it up, you can refer to the docs forlibavutil/error.candlibavutil/error.h.
|
I have the following issues when trying to compile thelibtheoraplayerdemo (av_player demo).
If someone can help me out with some errors from libtheoraplayer (), I would be really grateful.
| If you are familiar with linux then check the vlc source code it is free
but it is C code.
it may be help to you.
Thanks.
|
The problem is that the same code that compiles well on Windows, is unable to compile onUbuntu. Every time I get this error:
cc1: warnings being treated as errors
Now, it's big code base and I don't like fix all the warnings.
Is there a way I can compile successfully in spite of the warnings?
| Sure, find where-Werroris set and remove that flag. Then warnings will be only warnings.
|
I have the following issues when trying to compile thelibtheoraplayerdemo (av_player demo).
If someone can help me out with some errors from libtheoraplayer (), I would be really grateful.
| If you are familiar with linux then check the vlc source code it is free
but it is C code.
it may be help to you.
Thanks.
|
The problem is that the same code that compiles well on Windows, is unable to compile onUbuntu. Every time I get this error:
cc1: warnings being treated as errors
Now, it's big code base and I don't like fix all the warnings.
Is there a way I can compile successfully in spite of the warnings?
| Sure, find where-Werroris set and remove that flag. Then warnings will be only warnings.
|
I am writing a c++ application and trying to cross compile for arm:
sudo apt-get install gcc-4.4-arm-linux-gnueabi
However in the /usr/arm-linux-gnueabi/include directory I find no c++ directory. Can someone tell me where to find it?
| Install C++ compiler:
```
sudo apt-get install g++-4.4-arm-linux-gnueabi
```
|
I know that its possible to call functions in the native code from the java code, but what about vice-versa?
Is it possible for me to call a Java function from the native C code?
| Yes! You are interested in theJava Native Interface.
|
```
int main(void)
{
int x;
float y;
x=10;
y=4.0;
printf("%d\n",x/y);
return 0;
}
```
I compiled this code using a gcc compiler and when run I get 0 as output.Why is this code giving output as 0 instead of 2?
| IT's not the division, it's the print format.
Change:
```
printf("%d\n",x/y);
```
to:
```
printf("%f\n",x/y);
```
|
in C# I would just do:
```
private long[] myMethodName()
{
//etc
}
```
What is the equivalent in C?
This gives an error:
```
long[] readSeqFile(char *fileName)
```
| Typically for C you would pass a pointer and length
```
// returns number of elements written
size_t myMethodName(long* dest, size_t len)
{
//etc
}
```
|
Given the below declaration for pcap callback:
```
void my_callback(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
```
How to ascertain the total number of bytes present in the packet? I need that value so that I can pass it to crc32() function.
| according tothis referencethe information about the size of the packet is in thepcap_pkthdr's structure
|
I am creating a decompiler from IL (Compiled C#\VB code). Is there any way to create reference in C?
Edit:I want something faster than pointer like stack. Is there a thing like that?
| A reference is just a syntactically sugar-coated pointer–a pointer will do just fine.
|
I thought the result would be(2**32 - 1)
```
#include <stdio.h>
int main(){
unsigned int a = 0xffffffff;
printf("the size of int a %d\n",a);
return 0;
}
```
but it gives me-1, any idea?
| You're using the wrong format string.%dis a signed decimal int. You should use%u.
printfhas no knowledge of the types of variables you pass it. It's up to you to choose the right format strings.
|
I want to define a macro accepting either 1 or 2 parameters. Both the parameters should be different type. How to use ellipsis and read the arguments passed?
Below is the sample:
```
void test(char *var2)
{
printf("%s\n",var2);
}
#define PRINT_STRING(...) ( if (!var1) test(var2) )
int main(int argc, _TCHAR argv[]) {
PRINT_STRING(TRUE);
PRINT_STRING(FALSE,"Hello, World!");
return 0;
}
```
| This is known as aVariadic macro.
|
A certain parameter has3possible values, and there arensuch parameters with 3 values each. Need to create scenarios by randomly changing them and save each scenario as a text file, without any duplicated scenarios.
| Count from 0 to 3n-1, and convert your number to an n-digit base-3 number (including leading zeros). Each digit in the result represents the value for one parameter.
|
There is the well-knownJoint Strike Fighter(JSF) standard for C++. Is there a similar standard for C which promotes the use of C programmers' quality when coding for mission-critical platform?
| There isMISRA Cby the Motor Industry Software Reliability Association:
MISRA-C:2004,Guidelines for the use of the C language in critical systems
|
I need to convert a char * string of 3 characters ("123") to a float with two decimal places(1.23).
| You can use atoi, which will convert ASCII to Integer. Then convert that int to a float.
```
int num = atoi(string);
float f = num/100.0f;
printf ("%.2f", f);
```
|
I need to convert a char * string of 3 characters ("123") to a float with two decimal places(1.23).
| You can use atoi, which will convert ASCII to Integer. Then convert that int to a float.
```
int num = atoi(string);
float f = num/100.0f;
printf ("%.2f", f);
```
|
I want to have a function in C language file which can return string as output and I want to access that function from Managed Code i.e C# and get that string as return value. Any help or links related to this would be great for me.
| Is this a method in a common library, or a custom library? The more common ones can be found onpinvoke.net. If not, MSDN has an article onPlatform InvokingusingDllImportthat may be useful.
|
```
void foo(const gchar *a, ...)
{
do_something();
}
```
What does the...mean?
Does it only work with glib?
| It isvariable-length argument listwhich allows a function to have flexible number of arguments. It's part of the Standard. So it works everywhere that standard C is supported (or this feature itself is supported), not just glib.
|
For large files or other files that are not necessarily text, how can i compress them and what are the most efficient methods to check for data corruption? any tutorials on these kinds of algorithms would be greatly appreciated.
| For compression, LZO should be helpful. Easy to use and library easily available.
For data corruption check, CRC cahttp://cppgm.blogspot.in/2008/10/calculation-of-crc.html
|
How I can convert Java Object into C struct? I know that I can translate the data with XML but I need more quick and easy way to do this? What are the possible solutions?
| Data serialisation is the buzz word here.
For a quiet impressive list of techniques you might like to read here:http://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
|
Maybe I am misunderstanding the use of theP99library but what advantages does it provide over C11 (mainly concerned about multithreading) if anything more than being an emulator.
Speed?
Efficiency?
Or just backwards compat?
| The main advantage it provides over C11 is that it works with C99 compilers. C11 support doesn't really exist yet. It also provides many features that aren't in C11.
|
For large files or other files that are not necessarily text, how can i compress them and what are the most efficient methods to check for data corruption? any tutorials on these kinds of algorithms would be greatly appreciated.
| For compression, LZO should be helpful. Easy to use and library easily available.
For data corruption check, CRC cahttp://cppgm.blogspot.in/2008/10/calculation-of-crc.html
|
How I can convert Java Object into C struct? I know that I can translate the data with XML but I need more quick and easy way to do this? What are the possible solutions?
| Data serialisation is the buzz word here.
For a quiet impressive list of techniques you might like to read here:http://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats
|
I have an embedded board (beagleboard-xm) that runs ubuntu 12.04, I would like to read one GPIO input if it is logic 1 or 0. How can I implementcat /sys/class/gpio/gpio139/valuein C? (valuefile stores 0 or 1)I open the file by:
```
FILE *fp;
fp = fopen("/sys/class/gpio/gpio139/value", "rb");
```
what do I need to do next?
| If you want to read one character, try this:
```
int value = fgetc(fp);
/* error checking */
value = value - '0';
```
|
I'm using Qt creator 2.4. I need to use a string sayhi"world"in my code. I have tried to useQstringandstd::stringand I know/is the escape sequence character but the IDE doesn't understand it as an escape sequence and gives errors when I write:
```
"hi/"world/""
```
I can use any string format that can be converted intoQstring. Any ideas what I'm doing wrong?
| Use it like this:
```
QString output = "Hi \"world\"!";
```
|
What's the best practice for exiting C code on discovery of an error back to R? Package guidance says don't useexit(), which makes sense (as you kill everything), but how do you exit to R and indicate an error has occurred. Obviously you could have an error flag in the return vector, but is there a better way?
| You're looking forerror(). It's described inSection 6.2ofWriting R Extensions... and you should listen to your subconscious more often. ;-)
|
I know that there is a flag that can be used in makefile to include a header file in all the files which are being compiled, just like there is a -D flag to include a define. What flag is exactly for including header files. I don't remember know.
| In your compile command, you can use the-includeoption:
```
gcc -o main -include hello.h main.cpp
```
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:Left shifting with a negative shift count
On a 16-bit compiler, why does32<<-3or32>>-1result in 0?
what is the major reason for such a behaviour
| From K&R:
The shift operators << and >> perform left and right shifts of their
left operand by the number of bit positions given by the right operand,
which must be non-negative
|
I wrote a process explorer using C with GUI interface. I want to add a graph to show the CPU status. Which library or functions can help me to do that?
| You can useCairo, it's a simple 2D graphics library written in C.
|
can anyone suggest a openCV method which extract connected components in a 8bit single channel frame? is it cvBlobs suitable for this?
In addition to this i want to use it in C code.
| It seems thatcvFindContoursfunction can help you.
|
I've written several very helpful excel add-ins using VBA. I'm using Excel for Mac 2011 Version 14.2.2 (120421). I'd like to sell the add-ins via a web site. Can I write the add-ins in Xcode or do I have to use C#?
| FromMicrosoft Support:
In Office 2011 for Mac, there is no concept of add-ins. So using Excel Add-In is not possible...
You'll need to use VBA or AppleScript to emulate the same behavior.
|
can anyone suggest a openCV method which extract connected components in a 8bit single channel frame? is it cvBlobs suitable for this?
In addition to this i want to use it in C code.
| It seems thatcvFindContoursfunction can help you.
|
The following C code returns a "segmentation fault" error. I do not understand why it does not return the value 20. What is my error?
```
#include <stdio.h>
int main()
{
int* n;
*n = 20;
printf("%i\n",*n);
return 0;
}
```
| You haven't allocated memory ton, so
```
*n = 20;
```
attempts to write unspecified memory.
Try
```
#include <stdlib.h>
int *n = malloc(sizeof *n);
/* use n */
free(n);
```
|
I am trying out a C/C++ program, I want to know how much memory i am using due to heap and some other data structures. So how can I find out the amount of memory used by my various data structures?
I think that malloc operator should be overridden but I am not sure about the same.I am working on Linux and on Netbeans 7.1.
| You can use memory profilers for c++ like Valgrind as recommended in similar questions.
seethis
For netbeans IDE look atthis.
|
The following C code returns a "segmentation fault" error. I do not understand why it does not return the value 20. What is my error?
```
#include <stdio.h>
int main()
{
int* n;
*n = 20;
printf("%i\n",*n);
return 0;
}
```
| You haven't allocated memory ton, so
```
*n = 20;
```
attempts to write unspecified memory.
Try
```
#include <stdlib.h>
int *n = malloc(sizeof *n);
/* use n */
free(n);
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.