question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
How can I "compile" Objective-C Code to (only) C-Code?There is a way to preprocess Objective-C in Xcode (Product -> Generate Output -> Generate Preprocessed File), but this is not what I'm looking for...
Thanks...
| clang (the compiler front-end used by Xcode nowadays) has a-rewrite-objcoption built-in, which allows you to generate C++ code based on Objective-C (or Objective-C++) code.
Just don't ask me how to combine that with Xcode.
|
I have this code
whitespaces is a type int, so I can use the getchar function
```
do
{
...code...
whitespaces=getchar();}
while ( whitespaces != (EOF) || whitespaces!='\n');
```
but it doesnt exit the loop when i hit CTRL+Z (i am using windows 7)
what am I doing wrong?
EDIT : thank you, all of you...! very helpful
| You must use&&instead of||in thewhilecondition.
|
I have this code
whitespaces is a type int, so I can use the getchar function
```
do
{
...code...
whitespaces=getchar();}
while ( whitespaces != (EOF) || whitespaces!='\n');
```
but it doesnt exit the loop when i hit CTRL+Z (i am using windows 7)
what am I doing wrong?
EDIT : thank you, all of you...! very helpful
| You must use&&instead of||in thewhilecondition.
|
I came across the following line of code :
```
memcmp(mac, (char []){0x01,0x00,0x5E}, 3)
```
Maybe it will work ; Is it alright to code memcmp in the above manner ? Thanks.
| Yes, it will work, no problem, it's the same as:
```
char arr[] = {0x01,0x00,0x5E};
memcmp(mac, arr, 3);
```
|
Where can I found theplaces.sqlitefile database on Ubuntu/Linux 10.4, Firefox 5.0 (X11)?
I want read the open urls on firefox using C. But I not found the file. I tried followingthese instructions, but the.mozilladir does not exists in/home/<user>/folder.
| Try:
```
find / -name 'places.sqlite'
```
In my system the answer was:
```
/home/edu/.mozilla/firefox/qk8lh1kf.default/places.sqlite
```
|
I know that in the past there was an option-fprefix-function-namethat would add a prefix to all generated symbols, it doesn't seem to be part of gcc anymore. Is there any other way to do this?
| I believethis answerwill give you the solution.
In short, you can 'prefix' symbols in an existing library usingobjcopylike this:
objcopy --prefix-symbols=foo_ foo.o
|
How to include SVN revision of my project (not file revision) in C source code or in Makefile?
| We use a line like this in our makefile:
```
REPO_REV := $(shell svnversion -n)
```
That stores the revision number of the working copy into a make variable. To use it in C code, you can have your makefile use that value to define a macro on the compiler command line (something like-DREPO_REV=$(REPO_REV)for gcc).
|
Is there a tool or library which I can plot on C or C++ the vertex and edges of a graph like "plot" in R?
| GraphViz, a popular command-line graph drawing toolkit can theoretically be used as aC library- although I have never tried it.
|
Is there a way in C or Objective-C to convert presentation files (.ppt/.key) into a set of images?
many thanks!
| I doubt. ppt file is the fact XML style document. So if you want to parse it you have to write a XML parser who puts element in the exact position... So in fact you have to create your own powerpoint.
But, you might (both PowerPoint and Keynote) consider to export presentation to pdf, and then this will be a lot simpler.
|
```
#include<stdio.h>
int main()
{
struct value{
int bit1 : 1;
int bit3 : 4;
int bit4 : 4;
}bit={1,2,2};
printf("%d %d %d\n",bit.bit1,bit.bit3,bit.bit4);
return 0;
}
```
Output :
-1 2 2
Please explain the oupput of the program ?
| bit1is a signed 1-bit integer, that can hold the values-1and0only.
|
I want to get the user ID of a given process ID using C
How can I do it?
Any insight appreciated ;)
| If you have theprocfsfile system, then the effective user ID of the files in/proc/<pid>are that of the user.
|
I want to print time in the format hh:mm:ss:ms(milliseconds). I could print in the form of hh:mm:ss. What can be the way to print remaining milliseconds?
| ```
#include<sys/timeb.h>
#include<time.h>
int main(void) {
struct timeb tp;
ftime(&tp);
char timeString[80];
strftime(timeString, sizeof(timeString), "%H:%M:%S", localtime(&tp.time));
printf("%s:%d", timeString, tp.millitm);
return 0;
}
```
|
I want to get the user ID of a given process ID using C
How can I do it?
Any insight appreciated ;)
| If you have theprocfsfile system, then the effective user ID of the files in/proc/<pid>are that of the user.
|
How can I generate human readable llvm bitcode (extension .ll) from the binary llvm bitcode (extension .bc) file?
| Here is a useful link with all thellvm commands. Obviouslyllvm-disdoes what you ask.
|
I'm looking for a C function similar to the C# Array.Copy().
I found memcpy() only, but I need to copy from specific index too.
| If you have an array like this:
```
SomeType myArray[50];
```
And you want to copy elements indexed 19-29 (the 20th through 30th elements).
Then you do:
```
memcpy(dest, &myArray[19], 10 * sizeof(SomeType));
```
Note: this code-segment makes no provision for initializingmyArray, or allocating memory todest
|
How can I generate human readable llvm bitcode (extension .ll) from the binary llvm bitcode (extension .bc) file?
| Here is a useful link with all thellvm commands. Obviouslyllvm-disdoes what you ask.
|
Ok, suppose I want to store the address0xcdddd298in a C string so that it stores the bits for this address in little endian format. How would I do this? Would it be something like\x98d2ddcd?
| No. It would be"\x98\xd2\xdd\xcd".
But I'm not sure why you'd want to store an address in a string.
|
I use wcsncasecmp inside c/c++ app.
Compile have following error:
```
error: 'wcsncasecmp' was not declared in this scope
```
Gcc 4.2.1, macos.
How to solve this error?
| wcsncasecmpis a GNU-specific function. It's not available on Mac OS X.
|
Ok, suppose I want to store the address0xcdddd298in a C string so that it stores the bits for this address in little endian format. How would I do this? Would it be something like\x98d2ddcd?
| No. It would be"\x98\xd2\xdd\xcd".
But I'm not sure why you'd want to store an address in a string.
|
I saw the projectsshairportandshairport4wwhich stream music from an iDevice (called AirTunes/AirPlay by Apple) to a computer. I wanted to do the same for my media player. Those two projects are in C/C++/Perl and so I can't port them to C#/VB.
Can anyone explain me how the AirTunes protocol works and how do I implement it in .NET?
| This is old but may be a good starting point;
JustPort
First version ofAirfoilwas based onthis
|
I need to make a program which takes as input on text file and output the same string with one replaced word; the main function will take 3 parameters (wordR, wordS, file). So can anyone help me with a good tip how I can scan the words in c?
| Go with strtok() or strtok_r() function.
|
I would like to conditionally compile certain parts of code based on Compiler Type is there any macro for that?
Like this:
```
#if defined (COMPILER_TYPE e.g. GCC)
// Compile this
#elif defined (COMPILER_TYPE e.g. Visual Studio C Compiler)
// Else this
#endif
```
Thank you
| You can check if these macros are defined,__GNUC__for GCC and_MSC_VERfor MSVC.
|
I need to make a program which takes as input on text file and output the same string with one replaced word; the main function will take 3 parameters (wordR, wordS, file). So can anyone help me with a good tip how I can scan the words in c?
| Go with strtok() or strtok_r() function.
|
I would like to conditionally compile certain parts of code based on Compiler Type is there any macro for that?
Like this:
```
#if defined (COMPILER_TYPE e.g. GCC)
// Compile this
#elif defined (COMPILER_TYPE e.g. Visual Studio C Compiler)
// Else this
#endif
```
Thank you
| You can check if these macros are defined,__GNUC__for GCC and_MSC_VERfor MSVC.
|
I am creating an X11 window for a game, but it seems to only do the expose event once in a while (like maximizing and resizing), is there any way to have X11 call expose constantly? Kind of how glut has glutPostRedisplay()
| The expose event just tells you that a part of the window which was previously obscured is now visible, so you might need to redraw. There is no restriction that you redrawonlyat expose events.
|
In a terminal I get this:
```
manu@work:ulimit -s
manu@work:8192
```
Now in a Makefile, I have
```
test:
echo `ulimit -s`
```
An running make in the same terminal gives:
```
manu@work:make test
manu@work:unlimited
```
Why ? Does the make process changes it's own threads stack size ?
| setrlimit(R_LIMIT_STACK, ...);Alternatively, Linux also providesprlimitwhich can act as eithergetlimit,setrlimit, or both.
|
hi i am using lxscoket in iPhone to create sockets for iPhone. but here i am unable to find the last error which occurred.i am trying to use [err code] to find the error but it is not giving the error. so can any one please guide me in this.......
| using theerrnopresent in<sys/errno.h>we can find the last error.
|
I learned that Xcode can compile c code, that means can we write whole program in c?
| Yes. Objective C is a strict superset of C. This means that any C code is valid also in Objective C. But most of framework APIs are in Objective C, if you need to call these, you will have to include Objective C code as well. However standard C libraries are supported and even for 2D graphics there are Cocoa classes in C.
|
List of available LLVM passes are desribed here. I am interested in knowing which passes are included for different optimization levels. For example, for -O2 which passes are included. Is there any site or document which provides that information.
| It's visible inPassManagerBuilder.cppfile. Take a look at populateModulePassManager method where OptLevel is integer that follows -O option.
|
In C, semicolons (;) are used to indicate the end of the statement. Why do#includelines not need a semicolon?
| #include(and all other lines beginning with#like#define) is part of thepreprocessor. This is actually a separate programs that runs before the main compiler and does things likeincludefiles into the source and macro expansion.
|
i have used libxml2.Here when i am getting an XML data as a string i am unable to check whether it is a valid xml or a broken xml.so can anyone let me know how to check for the validation of xml in c using libxml2 or can suggest any more way to check for the validation.
| Have you tried theW3C Validator?
|
What would perror() be in the kernel? I can't tell what the error codes are from the error values ,i.e -22 alone.
| The Linux kernel just uses negated errno codes as a convention. So look inasm-generic/errno-base.horasm-generic/errno.hand find...
```
#define EINVAL 22 /* Invalid argument */
```
This can happen if you passNULLto a function that doesn't acceptNULL, for example. It depends on the function.
|
I'm looking for an open source library to detect the language used in an audio file, such as a wav file. After some searches I found Thishttp://sourceforge.net/projects/marf/files/Applications/%5Bg%5D%20LangIdentApp/from MARF ( Modular Audio Recognition Framework).. Someone had already use it?
| CheckCMU Sphinx Open Source Toolkit For Speech Recognitionthis project is quite active and in googles summer of code 2012.
|
I am trying to write a multi-threaded program in which I need to call the function crypt. But the compiler throws this warning. Also it doesn't recognize crypt_data as well. Any ideas?
| You need to include appropriate header file. In this casecrypt.h
```
#include <crypt.h>
```
|
I would like to ask you what's the most efficient way for checking user's input in C. I want the user to enter a 4 digit integer. How can I make sure that the user has entered exactly 4 digits and no letters?
| One way:
1) read asstringorchar*
2) check each char falls within 49-58 ASCII range.
Finally, convert intointusingatoi()(or atol() in case of long) if there are only four chars in the string and satisfy (2)
|
Is there a C function which can do the equivalent of find_first_not_of, receiving a string to search and a set of characters and returning the first character in the string that's not of the set?
| Thestrspnfunction will get you most of the way there. (You just have to massage the return value a bit.)
|
I'm starting to develop a client webservice in C/C++. I don't know which library to use. I've read about Axis2C and gSoap.
Any suggestion for developing a C/C++ SOAP webservice client? It seems that Axis2C is being discontinued.
| Stay away from Axis2. Use gSOAP. If the web service is simple, you might also trywsdlpullas it's pretty lightweight.
|
There is the POSIX library in c++ support wchar_t? if not, then how is it possible to solve this problem?
For example, I need openopendir(wchar_t*)
| There's no POSIX wchar_t version of opendir. Your platform may have one if you are lucky. Otherwise, you'll have to use something like the iconv library to convert your wide character string into UTF-8 (or whatever character encoding your file system API uses).
|
I'm starting to develop a client webservice in C/C++. I don't know which library to use. I've read about Axis2C and gSoap.
Any suggestion for developing a C/C++ SOAP webservice client? It seems that Axis2C is being discontinued.
| Stay away from Axis2. Use gSOAP. If the web service is simple, you might also trywsdlpullas it's pretty lightweight.
|
There is the POSIX library in c++ support wchar_t? if not, then how is it possible to solve this problem?
For example, I need openopendir(wchar_t*)
| There's no POSIX wchar_t version of opendir. Your platform may have one if you are lucky. Otherwise, you'll have to use something like the iconv library to convert your wide character string into UTF-8 (or whatever character encoding your file system API uses).
|
How can I run an AppleScript from within an C commandline utility?
Googling didn't work, it only gave meObjective-C solutions...
EDIT:Oops, I should have googled for 'run shell script C'...Now i found thesystem()function...
| I would use theexecfamily of functions, which is safer thansystem:
```
int exitCode = execlp("osascript", "osascript", "-e", "say \"Hello World\"", NULL);
```
|
Some C functions can modify the string value without that I pass the address of it.
For example:
```
char * s = "foo\0";
tobaa(s); /* Now foo is modified to something like "baa" */
printf("%s", s); /* baa */
```
How do I this?
| Simple:
```
void tobaa(char *s)
{
strcpy(s, "baa");
}
```
Also, the extra\0character is unnecessary, it is added automatically.
Also, make sure you pass a mutable buffer totobaaor you invoke UB.
|
I have a function as below
```
extern "C" int FuncTrace(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
return printf(fmt, args);
}
```
If I print some thing on console as below, it does not work?
```
FuncTrace(" %s \n", __PRETTY_FUNCTION__ );
```
Can someone help me correct the FuncTrace() ?
| You need thevprintffunction if you want to pass in ava_listpseudo-argument:
```
return vprintf(fmt, args);
```
|
How to set the boundaries of words usingSphinx?
For example, i want to find a phrase: "some."
ButSphinxfinds "something"!
I've tried to setSPH_MATCH_PHRASE):
```
sphinx_set_match_mode(sph, SPH_MATCH_PHRASE);
```
| I would suggest to use extended syntax: SPH_MATCH_EXTENDED2
And use phrase search operator like:
```
$cl->Query('"some"');
```
Check out the manual:http://sphinxsearch.com/docs/current.html#extended-syntax
|
Why is it necessary to specify the number of elements of a C-array when it is passed as a parameter to a function (10 in the following example)?
```
void myFun(int arr[][10]) {}
```
Is it so because the number of elements is needed to determine the address of the cell being accessed?
| Yes. It's becausearr[i][j]means((int *)arr)[i * N + j]ifarris anint [][N]: the pointer-arithmetic requires the length of a row.
|
I am writing a kernel module which forms its own packet at ip level and then sends the data . I just want to know how to find the ip address of a local network interface.
| There are defined ioctlsSIOCGIFADDR(to get if address) andSIOCSIFADDR(to set if address).
All device configuration for IPv4 is done innet/ipv4/devinet.c. You can refer to this source file to get more information.
|
I have a (C, Linux) application which handles Ctrl-C SIGINT by shutting down.
I'd like to add another signal handler so that I can use another keystroke combo for "reload configuration while running".
So I'm looking from a signal I can send to the foreground process by keystroke, which doesn't force the process to quit or suspend. Are there any others?
| You can usectrl+Z,
```
SIGTSTP
```
Value = 20
For more details refer thislink.
|
```
*(int *)CV = (int)0;
```
I was looking at a C code and can't understand this line of code. Could you interpret this and explain what it does?
| It castsCVto a pointer to anint, dereferences said pointer, and assigns the pointed-tointthe value0.
Here's a demo.Also,(int)0is the same as0in this situation, so that can be changed to make things a little simpler.
|
I have a (C, Linux) application which handles Ctrl-C SIGINT by shutting down.
I'd like to add another signal handler so that I can use another keystroke combo for "reload configuration while running".
So I'm looking from a signal I can send to the foreground process by keystroke, which doesn't force the process to quit or suspend. Are there any others?
| You can usectrl+Z,
```
SIGTSTP
```
Value = 20
For more details refer thislink.
|
```
*(int *)CV = (int)0;
```
I was looking at a C code and can't understand this line of code. Could you interpret this and explain what it does?
| It castsCVto a pointer to anint, dereferences said pointer, and assigns the pointed-tointthe value0.
Here's a demo.Also,(int)0is the same as0in this situation, so that can be changed to make things a little simpler.
|
I complied my program with only-goption, and add some libs like-lpthread
But when I use gdb to debug my program, using step it will step into some system functions, likeforkandmemcpy.
Is there a way to avoid that? It happens after I installvalgrindon my computer.
Kernel:2.6.38-13
| You need to run the following from a gdb prompt..
```
(gdb) set auto-solib-add off
```
It prevents gdb from loading symbols from libraries.
|
I complied my program with only-goption, and add some libs like-lpthread
But when I use gdb to debug my program, using step it will step into some system functions, likeforkandmemcpy.
Is there a way to avoid that? It happens after I installvalgrindon my computer.
Kernel:2.6.38-13
| You need to run the following from a gdb prompt..
```
(gdb) set auto-solib-add off
```
It prevents gdb from loading symbols from libraries.
|
I complied my program with only-goption, and add some libs like-lpthread
But when I use gdb to debug my program, using step it will step into some system functions, likeforkandmemcpy.
Is there a way to avoid that? It happens after I installvalgrindon my computer.
Kernel:2.6.38-13
| You need to run the following from a gdb prompt..
```
(gdb) set auto-solib-add off
```
It prevents gdb from loading symbols from libraries.
|
Someone can point me reliable method to run given application in different session of same user on Windows ?
I code in C.
Thanks in advance.
| The easiest way is to leverage Task Scheduler which can do this.
Use the method in this answer, but specify the local computer name, and a username and password:
start remote process within the context
You should specify that it doesn't interact with the desktop.
|
I am writing an LLVM pass which modifies the LLVM bitcode. For one variable, I want it to use a register, say R15 on x86. How can I instruct LLVM to use this register when generating machine code? Can this be instructed at the bitcode level?
| You can use inline assembler to model this requirement. There is no way to "tie" specific variable to register.
|
This Verilog tutorial(see the table at the end) suggests that{ }is a concatenation operator is C. I don't remember curly brackets as being anoperatorin C.
Is{ }a concatenation operator in C?
| No, that's just nonsense. No idea what that's about.
|
Will this leak memory?
```
char *str = "Hello/World";
char *pos = rindex(str, '/');
*pos = 0;
```
| No, but this will invoke undefined behavior as you are writing to a string literal. String literals are not required to be modifiable in C.
|
How can I create a buffer in linux kernel withoutmalloc()function (orcalloc()) and clean buffer withoutfree()function?
| You cannot use standard c library functions likemalloc()orcalloc()inside the kernel, The code you write in kernel links to the functionality provided by the kernel itself.
You can usekmalloc()& then free it withkfree().
|
I'm reading expert c, and got through setjump and longjump section, so want make the code running on my ubuntu 11.10, but when I include setjump.h, the gcc compiler complain that it can't find the header file, I find there is not a setjump.h in the /user/include/ directory.
So what should I do? Can you give me some suggestions?
| From thesetjmp(3)man page:
SYNOPSIS
#include <setjmp.h>
|
I'm building a voip app for iOS devices using the H.323 protocol and was wondering if there any libraries in Objective C (or C/C++) that let me convert my audio to H.323
| There are only 2 OpenSource H.323 libraries both C++:H323PlusandOPAL. And then there is the commercial Radvision SDK, which is done in C as far as I know.
|
How I would go about capturing/intercepting signals sent to another process from my own process? Willing to use C, Ruby, or any Linux package.
| You can write a library wrapper that will replace systemsignal/sigactioncalls to intercept setting of the signal handler and set your own handlers. On received signal, you can do your job and call user handler later. UseLD_PRELOADto replace systemsignal/sigactionroutines by your own.
|
For testing purposes, I need to share some definitions between Tcl and C. Is it possible to include C style include file in Tcl scripts? Any alternative suggestion will be welcomed, but I prefer not to write a parser for C header file.
| SWIG supports Tcl so possibly you can make use of that. Also I remember seeing some code to parse C headers on the Tcl wiki - so you might try looking at theParsing Cpage there. That should save you writing one from scratch.
|
I have declaredtypedef void (*DoRunTimeChecks)();
How do I store that as a field in a struct? How do I assign it? How do I call the fn()?
| Just put it in like you would any other field:
```
struct example {
int x;
DoRunTimeChecks y;
};
void Function(void)
{
}
struct example anExample = { 12, Function };
```
To assign to the field:
```
anExample.y = Function;
```
To call the function:
```
anExample.y();
```
|
For testing purposes, I need to share some definitions between Tcl and C. Is it possible to include C style include file in Tcl scripts? Any alternative suggestion will be welcomed, but I prefer not to write a parser for C header file.
| SWIG supports Tcl so possibly you can make use of that. Also I remember seeing some code to parse C headers on the Tcl wiki - so you might try looking at theParsing Cpage there. That should save you writing one from scratch.
|
I have declaredtypedef void (*DoRunTimeChecks)();
How do I store that as a field in a struct? How do I assign it? How do I call the fn()?
| Just put it in like you would any other field:
```
struct example {
int x;
DoRunTimeChecks y;
};
void Function(void)
{
}
struct example anExample = { 12, Function };
```
To assign to the field:
```
anExample.y = Function;
```
To call the function:
```
anExample.y();
```
|
For testing purposes, I need to share some definitions between Tcl and C. Is it possible to include C style include file in Tcl scripts? Any alternative suggestion will be welcomed, but I prefer not to write a parser for C header file.
| SWIG supports Tcl so possibly you can make use of that. Also I remember seeing some code to parse C headers on the Tcl wiki - so you might try looking at theParsing Cpage there. That should save you writing one from scratch.
|
I have declaredtypedef void (*DoRunTimeChecks)();
How do I store that as a field in a struct? How do I assign it? How do I call the fn()?
| Just put it in like you would any other field:
```
struct example {
int x;
DoRunTimeChecks y;
};
void Function(void)
{
}
struct example anExample = { 12, Function };
```
To assign to the field:
```
anExample.y = Function;
```
To call the function:
```
anExample.y();
```
|
I'm using MPI for performing parallel processing, after i compile the application using mpicc, where do i copy the executable file on other machines?
| You don't. The MPI implementation will invoke it for you on the remote machines when you call thempirun(or equivalent) command to launch your application.
|
i am making a module which would generate and transmit ip packets for voice. I know i had to set some value to the type of service field . what would be that value ?
| That value should bex.
|
I am searching for the way to download concrete pieces of file (e.q. first or last 1Mb) via bittorrent programmically.
C / C++, Java or Ruby libraries would be good solutions for me. Is there any solution in opensource world?
| Azureusis written in Java, and is provided onSourceForge
http://azureus.sourceforge.net/download.php
|
fromhere
```
48 struct snd_card *snd_cards[SNDRV_CARDS];
49 EXPORT_SYMBOL(snd_cards);
```
I am not getting whats the meaning of it and why that is used. I tried to search about it but not understanding the meaning of that.
| It makes a symbol accessible to dynamically loaded modules (provided that said modules add anexterndeclaration).
Not long ago,someone asked how to use it.
|
Basic question.. had to ask. Any help will be appreciated.
Q: Why can't I dereference the pointer to a multidimensional array like this:
```
int arr [2][2] = { {1, 2} , {3, 4} };
printf("%d ", *arr);
```
| Youcandereference it, it is just that the result is not going to be what you'd expect:*arris not anint, it's apointer to anint(OK, a one-dimensional array). If you want to see1printed, add another star:
```
printf("%d ", **arr);
```
|
I have seen thatXGetKeyboardMapping()would let me do that, but the documentation is opaque and I haven’t been able to find any examples. Any idea?
| You are looking for:
KeyCodeXKeysymToKeycode(display, keysym)
Display *display;
KeySym keysym;
keycode1 = XKeysymToKeycode(display, XK_dead_acute);
Also see this answer
|
I want to make a kernel module in which I would be able to send the packet from my kernel module. the thing is how should I populate the network_header, transport header and mac header?
| If you are not so much concerned with the mac header, then have a look at this code to generate the packetsGenerating packets
|
What will be the order the function calls in the following expression:
```
a = f1(23, 14) * f2(12/4) + f3();
```
Does it depend on the compiler?
| Order of evaluation of each operand isunspecifiedin C and C++, which means, in your case, the order of function calling isunspecifiedas per the Standards.
Note that it isunspecified,notimplementation-defined.
|
is it possible to do calculation like this in C?
```
A*exp(i*(b+c)) + D*exp(i*(e+f)),
```
where A,b,c,D,e,f are real numbers.
| C99 introduces support for complex numbers. Whether or not your compiler implements this feature I don't know.
|
I am using open/read functions, there's feof for fopen/fread to detect end-of-file, what's the equivalent way for open/read?
| Fromman read:
On success, the number of bytes read is returned (zero indicates end of file), ...
|
I was wondering if there are any compilers that support a considerable amount of the new C11 standard. Looking for features like Generic Selection etc.
Any suggestions?
| Pelles C version 7.00 (Release Candidate is available now)
http://www.smorgasbordet.com/pellesc/
|
I was wondering if there are any compilers that support a considerable amount of the new C11 standard. Looking for features like Generic Selection etc.
Any suggestions?
| Pelles C version 7.00 (Release Candidate is available now)
http://www.smorgasbordet.com/pellesc/
|
I know I can read off /proc/[id]/maps but I'm not sure if the first entry is always the .text section.I would have to parse /proc/[id]/maps, is there an api I could call to get the data?
edit- I see pmap just reads that same file. No worries. I'll just read off the first two integers.
| Solved as per above. (these are extra characters to get past the padding.)
|
I want to write a simple program that takes a moderately sized wav file (60 seconds or so) and cuts it into 1 second length segments of the same format (1.wav,2.wav,... etc) ... Is there a simple C++ or java library that could do this? I don't want to have to manipulate header information
| Shell script wrapped around theffmpegcommand line utility. Also,sox.
http://sox.sourceforge.net/
|
Does it actually read character by character or does it read some bytes into the kernel buffer and return to the user- character by character?
Is it the same withfgets?
Let me say I use glibc and a gcc compiler.
| Almost right. A typical modern implementation that does have a user/kernel separation stores the bytesin a user buffer, not in a kernel buffer. Thus many calls tofgetcactually trigger few true system calls.
|
I am working with a standard library with many files. I would like to know where an often-used typedef struct is defined. I have its name, but that's it.
Is there a way to "programmatically" tell where a givenstructis defined among a lot of files?
| You didn't list an OS or an IDE but in Linux I have always usedgrep. I have yet to find an IDE that is good at tracking down typedefs especially since some are wrapped in macros.
|
Inthis example codeit deals with framebuffers before setting up the context.
I've read the man pages of the functions, but I still don't understand exactly what's going on.
So my question is,what exactly is a framebuffer in GLX and how significant is configuring it?
| A framebuffer is an area of memory that holds a displayable image. You need one when creating an OpenGL context so that OpenGL has a place to store the image it renders.
|
In windows programming, how can we find out the number of partitions and the name of each partition on the hard drive?
| You can use theDeviceIoControlfunction with theIOCTL_DISK_GET_DRIVE_LAYOUT_EXcontol code to get a list of partitions.
|
In windows programming, how can we find out the number of partitions and the name of each partition on the hard drive?
| You can use theDeviceIoControlfunction with theIOCTL_DISK_GET_DRIVE_LAYOUT_EXcontol code to get a list of partitions.
|
I am proceeding to make a code for handling multiple clients in socket programming but i am not having idea for even the algorithm. I dont know how to proceed. Can anyone help me with the algorithm ?
Thanks in Advance
| I would download the Apache code - It achieves this and seems to be a reasonable algorithm.
|
If my string contains:
```
a="abd\\aa\[1\]\\"
```
and if I try to write it to a file usingfputsandfprintf, it writes the following to the file:
```
"abd\aa[1]\"
```
I want"abd\\aa\[1\]\\"to be written to the file. How can I accomplish this?
| You have to escape your\, like so:
```
printf("abd\\a[1]\\");
```
Or elseprintfwill print\awhich is theBELcharacter.
|
When using plain C in iPhone development, does the compiler place the variables declared asregisterin a CPU register?
| The only way to know for sure is to look at the documentation for the compiler and if that doesn't describe whatregisterdoes then it could do anything (within the parameters defined by the standard).
|
For example, an input would be 2095 and I want 20 as an output. Thanks.
| You can always scan 2 characters into an int
```
scanf("%2d", &num);
```
or if you already have the number
```
while (num >= 100) num /= 10;
```
This will give you the first 2 digits in number form.
|
I am trying todisplay a compile-time message in GCC, via
```
#pragma message "hello world"
```
But when I compile with-Wallit gives the warning
```
warning: ignoring #pragma message
```
I'm using GCC 4.2.1 on Mac OS X 10.6.8 (Snow Leopard).
Why isn't it displaying the message? How can I make it display the message?
| If you read thecorrect documentation, you'll find that#pragma messageisn't supported in GCC 4.2.1.
|
I have been using the alarm() system call and an alarm handler in my c program. Recently I decided that I wanted to set the alarm for a time less than a second, so I passed it 0.5, and discovered that the alarm() function accepts an unsigned int. Is it possible to set an alarm for less than a second?
| Use theualarm(usecs, interval)method instead.
|
Please let me know how to round a decimal number like 0.53124 to a nearest multiple of 1/16 which is 0.5. And similarly, when you round 0.46875 we must get 0.5. Thanks
| ```
floor(0.53124 * 16 + 0.5) / 16
floor(0.46875 * 16 + 0.5) / 16
floor(x * 16 + 0.5) / 16
```
|
This question already has answers here:How to find the size of an array (from a pointer pointing to the first element array)?(17 answers)Closed9 years ago.
```
char* username
```
is a pointer to the beginning of a character array (in c).
How do I calculate the size of the array, is there is function that can do it?
| use strlen(username). But the array has to terminated by '\0'. Otherwise you cannot do that.
|
Using GDB on the command line, I sometimes break at a certain line of code. At that breakpoint, I can then call functionsas ifmy executable contained the call.
How can I get GDB to print the list of all the possible functions that are callable at a given breakpoint?
| You could typecalland then hit<tab>(until a list displays). This seems to list the functions contained in the binary.
|
I am trying todisplay a compile-time message in GCC, via
```
#pragma message "hello world"
```
But when I compile with-Wallit gives the warning
```
warning: ignoring #pragma message
```
I'm using GCC 4.2.1 on Mac OS X 10.6.8 (Snow Leopard).
Why isn't it displaying the message? How can I make it display the message?
| If you read thecorrect documentation, you'll find that#pragma messageisn't supported in GCC 4.2.1.
|
I have been using the alarm() system call and an alarm handler in my c program. Recently I decided that I wanted to set the alarm for a time less than a second, so I passed it 0.5, and discovered that the alarm() function accepts an unsigned int. Is it possible to set an alarm for less than a second?
| Use theualarm(usecs, interval)method instead.
|
Please let me know how to round a decimal number like 0.53124 to a nearest multiple of 1/16 which is 0.5. And similarly, when you round 0.46875 we must get 0.5. Thanks
| ```
floor(0.53124 * 16 + 0.5) / 16
floor(0.46875 * 16 + 0.5) / 16
floor(x * 16 + 0.5) / 16
```
|
If I try to executes these commands:
```
int main(int argc, char* argv[])
{
execl("/bin/echo","echo","list ","of", "files:\n",NULL);
execl("/bin/ls","ls","-al",NULL);
return 0;
}
```
Only the first one gets executed, why?
| execl REPLACES the current process - it's not a subroutine. You might try usingsystem()instead.
|
I am debugging a program using gdb. First Iloadmy executable, then Icontinueto run the program. I sometimes want to interrupt execution of my program, so I doCtrl + C.
My problem is that this closesbothmy program and gdb. How can I exit my program without exiting gdb?
| Have you tried to usekillfrom inside gdb?
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.