question
stringlengths
24
425
answer
stringlengths
5
405
I am reusing a legacy C library in an iOS app and in an Android app. I want to customize some macro definitions (e.g. for logging). Are there standard defines to check for (using #ifdef) whether the code is being compiled for iOS or Android/NDK?
__ANDROID__orANDROIDfor Android (compilation with the NDK) and__APPLE__on Apple platforms (iOS or OSX)
I'm desperately looking for some C sample source code that describes how to implement a HID client using Bluez. More specifically, I would like to know how to write an application that sends keyboard inputs over bluetooth to another Linux system. (Really, the fact that the receiver is running Linux/Bluez shouldn't matter.) -Cheers
hidclienthttp://anselm.hoffmeister.be/computer/hidclient/index.html.en?
I'm searching for theomp.hfile for using it in eclipse. I failed to find it in openmp.org. Where do I findomp.h? thanks.
Under Linux, you can find a file by ``` locate omp.h ``` Have you tried to simply use it with ``` #include <omp.h> ``` and add the openmp flag to your g++ compiler flag? ``` g++ -fopenmp sample.c ```
I was wondering if the WinAPI or something has a way to get the raw data from a USB device, or something that would lead me in the right direction for this sort of thing. for example, for an midi device, this data might be the velocity, and which note was hit. Thanks
Not directly but you can now useusblibon windows
I may have missed something but I see here on header files all kinds of functions to move text around in C++ but not on the C API. How is it done? EDIT: Pixmap fonts for example.
TryglTranslatef()orglRasterPos2f(). Also, what documentation are you looking at?I'm not seeing any positioning functionality.
I have two C files. I want to declare a variable in one, then be able to access it from another C file. My definition of theexamplestring might not be perfect, but you get the idea. ``` //file1.c char *hello="hello"; ``` ``` //file2.c printf("%s",hello); ```
``` // file1.h #ifndef FILE1_H #define FILE1_H extern char* hello; #endif // file1.c // as before // file2.c #include "file1.h" // the rest as before ```
If I have ``` char input[50] = "xFFFF"; int a; ``` How can I store the numerical value of input in a? the language is C.
One way to do it might be: ``` if (sscanf(input, "x%x", &a) == 0) { /* matching failed */ } ``` If your input uses a real hex specifier (like "0xFFFF") you can just use %i: ``` if (sscanf(input, "%i", &a) == 0) { /* matching failed */ } ```
I have a c program with say n number of for loops. How many processes and child processes will be running for this program and how?
A for loop does not fork a new process. N number of for loop should run in a single process.
I have to call a c function declared in a lib file from c++. What instructions/attributes/configuration I have to set for this?
Do you have a header file for the library? If so it should have ``` extern "C" { blah blah } ``` stuff in it to allow it to be used by C programs. If not, then you can put that around the include statement for the header in your own code. E.g. ``` extern "C" { #include "imported_c_library.h" } ```
I need to intake a number like: 200939915 After doing this, which I know how, I need to remove the first number so it becomes: 00939915 What is the best way to do this?
``` char *c = "200939915"; char *d = c + 1; ```
I need to intake a number like: 200939915 After doing this, which I know how, I need to remove the first number so it becomes: 00939915 What is the best way to do this?
``` char *c = "200939915"; char *d = c + 1; ```
``` #include <semaphore.h> sem_t mutex; int main (int argc, char * argv[]) { sem_init (&mutex,0,1); } ``` I'm getting: ``` /tmp/ccAMFxDX.o: In function `main': programaservidor.c:(.text+0x86): undefined reference to `sem_init' collect2: ld returned 1 exit status ```
Per the sem_init() man page Link with -lrt or -pthread. As ingcc your_code.c -lpthread -o your_code
To use pthreads, I used as input a char* that was cast to void* as input. If it's later cast to (char*) it can be printed and used normally ( (char*)var ). However, if one does (char*)var[i], where 'i' will help us reference a character, it doesn't. Why? e.g. MS says 'expression must be a pointer to a complete object type'.
Because of operator precedence: the cast comes after the subscript operator. You have to write((char*)var)[i];.
Is there any way to speed up getting an array size in C? Typing outsizeof(array)/sizeof(int)every time gets old. Do any C libraries have something like.lengthor is there some way I can definesizeof(array)/sizeof(int)as a shorter constant of some sort (possible also using dot notation)?
You can usesizeof(array)/sizeof(*array)and make a macro. ``` #define length(array) (sizeof(array)/sizeof(*(array))) ```
I have been looking through the Lua source code, and I think that is how it works.
Lua and C use a stack to exchange arguments. Many script languages use this way to communicate with C program.
I am trying to debug a file that has had its symbols stripped. I have headers for the file, with offsets for each function, and was wondering if it was possible to create a DSYM file using these headers. I cannot set breakpoints on the offsets because the file is a plugin, so the functions are mapped to a different location in memory.
Simply put, it is not.
I am working with graphics in C. I find thinking about the pixel locations terrible and I am in need of a tool where I can draw images and it gives me the pixel location of that point. Please guide me.
Paint that comes with Windows provides pixel locations in its status bar.
How to print the environment variables in a C program usingenviron. ``` extern char **environ ```
``` #include <unistd.h> #include <stdio.h> extern char **environ; //... int i = 0; while(environ[i]) { printf("%s\n", environ[i++]); // prints in form of "variable=value" } ```
Common programs like gcc, rm, cp etc. seem to follow a pattern in reporting their errors like this: program: error For instance: ``` $ gcc gcc: no input files ``` Is there some standard function or macro I should call from within my own C programs to report errors in a standard fashion?
There are no macros (that I know of). But, here's the relevantstandardfor formatting error output.
I have a file called "main.c". Whats the simplest Makefile I can have to compile this file into an executable that I can run like./blah?
``` all: gcc -o blah main.c ``` You don't need makefile here, simple shell script is OK.
I have been looking through the Lua source code, and I think that is how it works.
Lua and C use a stack to exchange arguments. Many script languages use this way to communicate with C program.
I am trying to debug a file that has had its symbols stripped. I have headers for the file, with offsets for each function, and was wondering if it was possible to create a DSYM file using these headers. I cannot set breakpoints on the offsets because the file is a plugin, so the functions are mapped to a different location in memory.
Simply put, it is not.
I am working with graphics in C. I find thinking about the pixel locations terrible and I am in need of a tool where I can draw images and it gives me the pixel location of that point. Please guide me.
Paint that comes with Windows provides pixel locations in its status bar.
How to print the environment variables in a C program usingenviron. ``` extern char **environ ```
``` #include <unistd.h> #include <stdio.h> extern char **environ; //... int i = 0; while(environ[i]) { printf("%s\n", environ[i++]); // prints in form of "variable=value" } ```
Common programs like gcc, rm, cp etc. seem to follow a pattern in reporting their errors like this: program: error For instance: ``` $ gcc gcc: no input files ``` Is there some standard function or macro I should call from within my own C programs to report errors in a standard fashion?
There are no macros (that I know of). But, here's the relevantstandardfor formatting error output.
I saw this function in thelua.cfile calleddotty(). I have a feeling that it takes line-by-line input, is this correct?
That's correct, it's basically theREPL. That function technically works on a chunk-by-chunk basis. Theloadlinefunction does the actual line-by-line input, until it gets a complete chunk to execute.
ulimit -s shows the defaultstacksizelimit. Is there a startup defaultheapsize ?
no in 32-bit Linux, every process see a continuous 4GB space. most of it isn't mapped to real RAM, but gets mapped on usage. in 64-bit it's similar but much bigger.
I am studying for an OS quiz and I did not understand what output ``` if(fork()) fork() ``` will produce. Can someone explain? I didn't understand this line: ``` if(fork()) ``` Edit: What I meant with "output" is how many processes will be there if this code was executed. Sorry I'm a bit dizzy after studying.
Here's a hint:if (fork())is just a short way of writingif (fork() != 0).
How do I get the output from the following: ``` lua_pushstring(L,"print(i)"); lua_call(L,0,0); ```
If you want to run arbitrary Lua code from C, what you need to use isluaL_dostring, as in this question:C & Lua: luaL_dostring return value Edit: please note that Lua's defaultprintfunction will still print its output straight to the console. You will need to redirect stdout in some way (probably to a pipe) if you want to capture its output.
I am using Xcode (mac) and I want to import my own header file inside of a C project. How do I do this?
With your project open, go to theProjectmenu, chooseAdd to Project..., browse to the header file you want to add, on the next dialog click thecopy into destination group's folder(assuming the file is NOT within your project's path), then click theAddbutton. The file will now appear within your project.
In my programming project I want to parse command line attributes using flex/bison. My program is called like this: ``` ./prog -a "(1, 2, 3)(4, 5)(6, 7, 8)" filename ``` Is it possible to parse this string using flex/bison without writing it to a file and parsing that file?
See this questionString input to flex lexer
I am aware thatfoo[bar]is equal to*(foo + bar), but what is*foo[bar]equal to, such as accessing*argv[2]? I am somewhat confused in understanding this, I assumed maybe something like*(*(foo) + bar)but am unsure.. I apologize if this is a simple answer.
*a[b]is equivalent to*(a[b])due to C and C++ precedence rules. so*a[b]is equivalent to**(a+b)
Is it possible for a program written in C (or assembly) and is linked with c stdlib using gcc to print the address of its entry? (Since the _start symbol denotes the program entry actually i ask if its possible to print the address of that symbol from inside the main function without using parsing of ELF executable file.)?
I question why you need to do this, but have you tried usingdlsymfor your purposes?
I want to define a constant string containing non printable characters in C. For e.g - Let say I have a string ``` char str1[] ={0x01, 0x05, 0x0A, 0x15}; ``` Now I want to define it like this ``` char *str2 = "<??>" ``` What should I write in place of<??>do define an string equivalent tostr1?
You can use"\x01\x05\x0a\x15"
Where to search for free C/C++ libraries?
trySourceforge avoidGPL, as they aren't really free and are spreading like a virus through the rest of your project useLGPL
Hey all, I need to compare a double inside an if statement. If the double has no value/is equal to zero, it should do nothing. Otherwise it should do something. My if statement if (doubleNameHere > 0) doesn't work. Obviously I'm missing something fundamental here, any ideas?
Sorry all, it turns out that it wasn't set to zero, it was equal to another blank double value. I started it at zero and it was fine.
How would I load a chunk of Lua code as acharand run it using this function? If not, what other function can I use and how doeslua_load()work?
UseluaL_dofileandluaL_dostringto load and run Lua code. Read their definitions inlauxlib.hto see how these are implemented in terms of lower-level primitives. To learn howlua_loadworks, read the code ofluaL_loadfileandluaL_loadstring.
If I define a function in filefunc1.c, and I want to call it from filecall.c. How can I accomplish this task?
You would put a declaration for the function in the filefunc1.h, and add#include "func1.h"incall.c. Then you would compile or linkfunc1.candcall.ctogether (details depend on which C system).
How do I generate all possible permutations of a list of numbers in C? As an example,[1, 8, 12]would generate ``` [1, 12, 8], [12, 8, 1], [12, 1, 8], ... ```
Have a look at thisJohnson-Trotter Algorithmand applet it is exactly what you want.
I'm confused in this program how the value of x=320 ... ``` #include<stdio.h> int a=5; int main(){ int x; x=~a+a&a+a<<a; printf("%d",x); return 0; } ``` http://codepad.org/UBgkwdYl hoping for quick and positive response..
This is evaluated like this: ``` x = ((~a) + a) & ((a + a) << a); ``` You should review the C operator precedence tables.
would it make any difference if i use c-style functions to search an array or cstring?
In a character string (cstring), the NULL character at the end acts as a sentinel, to signify the end of the search. If it's an array of characters without the terminating NULL character, then you had better know the length of the string, to avoid overflow.
XL Compiler of AIX seems to have the-qfuncsectoption which places each function in a seperate object control section with the effect that when the final executable is created it helps in removing unwanted functions. Is there an equivalent option for the same in gcc? I am unable to find the same.
``` -ffunction-sections -fdata-sections ``` http://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Optimize-Options.html
``` enum FileOpenFlags { FileOpenFlags_Create = 1, FileOpenFlags_Truncate = 2, }; FileOpenFlags flags = FileOpenFlags_Create | FileOpenFlags_Truncate; ``` Is it true the return type ofenum |is alsoenum??
No, the above expression will have the typeint. However, sinceenums convert to and fromintwithout problems, it's then implicitly converted back toenumfor the store. See alsothis comp.lang.c FAQ entry.
I am usinglibcurlto create an http connection to anamfphpserver. Do I have to set the content type to any specific format? I noticed there is a option calledAMFPHP_CONTENT_TYPEin PHP cURL but I couldn't find a corresponding value inC.
Found it. I have to addContent-type: application/x-amfto thePOSTheader.
I'm interested in reviewing some of the functions included in the string library for c, but I can't find the source code (literally, i.e. functions and all) online and I have no idea where to find it. Thanks. EDIT: thelink provided by pmgshows those functions divided into c files, so it's about what I needed. Thanks.
Take a look atredhat glibc. It appears to be somewhat current.
Can you tell me what is the meaning of " Java-class-file loader library in C"? It's a homework assignment and I am not sure how I should approach it. Update:I just found out a link ongithubwhich exactly defines the topic but I still need some help to figure out what exactly this means?
I suppose it's about a C library which provides an API for loading Java .class files. This should be possible usingJNI.
On this link I came acrosshttp://lxr.linux.no/#linux+v2.6.36/include/linux/pci.h#L299integer declarationunsigned int is_added:1;I have made C programs and declared integers in them but in the above I see use of:What sort of syntax is that?
I think you have come across abit-field:)
I was wondering if there are some recommendedread-eval-print loop (REPL)respectively for (1) C++ (2) C (3) Java Thanks!
C and C++ You can use CERN'scint. Java You can useBeanShell, or if you don't care so much about having Java syntax (e.g. your goal is just to make sure theclassesdo what you want), you can use Groovy, Scala, JRuby, or Jython.
I have an integer, retrieved from a file using fscanf. How do I write this into a binary file as a two-byte integer in hex?
This will write a short integer to a binary file. The result is 2 bytes of binary data (Endianness dependent on the system). ``` int main(int argc, char* argv[]) { short i; FILE *fh; i = 1234; fh = fopen( argv[1], "wb" ); fwrite( &i, sizeof( i ), 1, fh ); fclose(fh); } ```
What is the best (shortest) way to read the next non-blank (not space/newline/tab) character from a file in a C program? I realize I could probably use gets followed by strtok, but it seems like there has to be something more concise. If so, let me know; if not, let me know that too. Thanks.
``` char c; fscanf(f, " %c", &c); ``` OR ``` int c; while (isspace(c=fgetc(f))); ```
I'm trying to make a Lua compiler for Mac OSX with an interface written in Objective-C and the Lua source code written in C.
You already are combining C and Objective C. No extra effort is needed.
How can I make a control using bitmaps which changes when I drag with the mouse (e.g. a rotating knob)? And this using the Win32 API?
Write code to recognize the WM_MOUSEWHEEL message in your control's window procedure.
I have char aa[] = { "Hello, !" }; char bb[] = { "World" }; How to insert bb into aa the most efficiently with cstring ?
allocate big enough buffer (malloc/new[])copy the first part of the aa string into the buffer (strncpy/memcpy)copy the bb string (strcpy/memcpy)copy the rest of the aa string (strncpy/memcpy)
How could I make a line of code that would exit out of my program after input is given by the user for a specific word? the psuedo-code of what I have is as follows: take input; compare (input) to exit word; if input is same as exit word exit the program <------- help here; else rest of program;
If the code is inside main, you can simply usereturnif somewhere else useexit
I need one server to receive ip requests from clients(there are not in the same intranet), and I can route all the response packets to a special gateway server, and then I send the response packages to clients after some processing. it is like VPN, but I want to do some development based one opensource project, so i can control it myself. any suggestion? thanks!
There isOpenVPNwhich is as the name already suggests open source.
How in C can we read and makeDWORDvariables with a low and high word and low and high byte?
WinAPI provides macros for the manipulations of these types, such as: HIWORDLOWORDMAKELPARAM
How would I get a string representation of a web page's source from URL in C?
If you just want to download it,libcurlis a pretty nifty library for fetching files from many different kinds of servers, including HTTP.
I know i can set an alarm to "go off" with a SIGALRM after a specified amount of time usingalram(numberOfSeconds)what i am looking to do is to raise the SIGALRM immediately. Any help would be greatly appreciated.
raise(SIGALRM);
If I call: ``` ./program hello world ``` then: ``` argc would be 3. argv[0] would be "./program". argv[1] would be "hello". argv[2] would be "world". ``` What's the purpose of passing "./program" as an argument? In fact, it's not an argument at all!
You can make symbolic links to the same binary. Depending on what link you use, you will get different behaviour. Busybox is an example of this.
given a pointer to unsigned char value,*ptr. How to copy its whole value to new char valuechar buff;in a correct way (malloc etc), without looping for each character? Any way to retreive the memory amount currently allocated for the pointer value?
If you really have a single character: ``` char buff = (char)*ptr; ``` If you have a string which i assume as you are talking about looping over characters: ``` char *buff = strdup(ptr); ```
How would I get a string representation of a web page's source from URL in C?
If you just want to download it,libcurlis a pretty nifty library for fetching files from many different kinds of servers, including HTTP.
I know i can set an alarm to "go off" with a SIGALRM after a specified amount of time usingalram(numberOfSeconds)what i am looking to do is to raise the SIGALRM immediately. Any help would be greatly appreciated.
raise(SIGALRM);
If I call: ``` ./program hello world ``` then: ``` argc would be 3. argv[0] would be "./program". argv[1] would be "hello". argv[2] would be "world". ``` What's the purpose of passing "./program" as an argument? In fact, it's not an argument at all!
You can make symbolic links to the same binary. Depending on what link you use, you will get different behaviour. Busybox is an example of this.
given a pointer to unsigned char value,*ptr. How to copy its whole value to new char valuechar buff;in a correct way (malloc etc), without looping for each character? Any way to retreive the memory amount currently allocated for the pointer value?
If you really have a single character: ``` char buff = (char)*ptr; ``` If you have a string which i assume as you are talking about looping over characters: ``` char *buff = strdup(ptr); ```
I know i can set an alarm to "go off" with a SIGALRM after a specified amount of time usingalram(numberOfSeconds)what i am looking to do is to raise the SIGALRM immediately. Any help would be greatly appreciated.
raise(SIGALRM);
If I call: ``` ./program hello world ``` then: ``` argc would be 3. argv[0] would be "./program". argv[1] would be "hello". argv[2] would be "world". ``` What's the purpose of passing "./program" as an argument? In fact, it's not an argument at all!
You can make symbolic links to the same binary. Depending on what link you use, you will get different behaviour. Busybox is an example of this.
given a pointer to unsigned char value,*ptr. How to copy its whole value to new char valuechar buff;in a correct way (malloc etc), without looping for each character? Any way to retreive the memory amount currently allocated for the pointer value?
If you really have a single character: ``` char buff = (char)*ptr; ``` If you have a string which i assume as you are talking about looping over characters: ``` char *buff = strdup(ptr); ```
``` int main() { char *temp = "Paras"; int i; i=0; temp[3]='F'; for (i =0 ; i < 5 ; i++ ) printf("%c\n", temp[i]); return 0; } ``` Whytemp[3]='F';will cause segmentation fault sincetempis notconst?
You are not allowed to modify string literals.
What would be the fastest/shortest way to create a string of repeating characters. For instance,n = 10, char = '*', resulting allocated string: **********
Usememset. ``` int n = 10; char c = '*'; char* buf = malloc(n+1); memset(buf, c, n); buf[n] = '\0'; free(buf); ```
I'm trying to get theCPU serialormotherboard serialusingCorPythonfor licensing purposes. Is it possible? I'm usingLinux.
Under Linux, you could use "lshw -quiet -xml" and parse its output. You'll find plenty of system information here: cpuid, motherboard id and much more.
This question already has answers here:Copying a part of a string (substring) in C(13 answers)Closed9 years ago. For example, I have this ``` char *buff = "this is a test string"; ``` and want to get"test". How can I do that?
``` char subbuff[5]; memcpy( subbuff, &buff[10], 4 ); subbuff[4] = '\0'; ``` Job done :)
``` zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &r1, &n, &r2, &m) ``` What's"ss"for here?
The type specifier in your case is"ss". The specifiersis for a string. Since you are requestingtwostring parameters you need to supply twosasss: ``` zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &field1 &field1_length, &field2, &field2_length) ```
Is there any way to change anintfile descriptor to aFILEstruct pointer or/and changeFILE*to a file descriptor in C?
The functionfdopen()returns a new (FILE *) associated with an open file descriptor. The functionfileno()returns the file descriptor associated with an open FILE *.
I am using MSVS 2008. I am writing an application in c, and would like to know whats the best way to determine hard disk information such as space available and total capacity. Thanks
The Win32 API reference is where you should be looking. The call for free space isGetDiskFreeSpaceEx()
Since a function in C returns only one value, all the time, how canfork(), which is also a function, return two values?
The fork function returns 0 to the child process that was created and returns the childs ID to the parent process. The two seperate processes are each returned a single value. So think of it more as one return being called on eachthreadprocess.
I am seeking for a C library that does approximate string matching. Calculating Levenshtein distance for example. My query strings will be ~512 bytes. I know aboutFlamingobut it is C++.
Not a library but simple function you findhere A GPL Version
``` $ getconf BUFSIZ getconf: Unrecognized variable 'BUFSIZ' ``` Is there a standard way to determine the value of BUFSIZ from a shell? It's easy enough to write a simple C program to output the value, but I don't quite understand why getconf doesn't do it.
Because BUFSIZ is a somewhat-arbitary configuration parameter for the stdio library, and not a system configuration parameter
I'm trying to get theCPU serialormotherboard serialusingCorPythonfor licensing purposes. Is it possible? I'm usingLinux.
Under Linux, you could use "lshw -quiet -xml" and parse its output. You'll find plenty of system information here: cpuid, motherboard id and much more.
This question already has answers here:Copying a part of a string (substring) in C(13 answers)Closed9 years ago. For example, I have this ``` char *buff = "this is a test string"; ``` and want to get"test". How can I do that?
``` char subbuff[5]; memcpy( subbuff, &buff[10], 4 ); subbuff[4] = '\0'; ``` Job done :)
``` zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &r1, &n, &r2, &m) ``` What's"ss"for here?
The type specifier in your case is"ss". The specifiersis for a string. Since you are requestingtwostring parameters you need to supply twosasss: ``` zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &field1 &field1_length, &field2, &field2_length) ```
Is there any way to change anintfile descriptor to aFILEstruct pointer or/and changeFILE*to a file descriptor in C?
The functionfdopen()returns a new (FILE *) associated with an open file descriptor. The functionfileno()returns the file descriptor associated with an open FILE *.
I am using MSVS 2008. I am writing an application in c, and would like to know whats the best way to determine hard disk information such as space available and total capacity. Thanks
The Win32 API reference is where you should be looking. The call for free space isGetDiskFreeSpaceEx()
Since a function in C returns only one value, all the time, how canfork(), which is also a function, return two values?
The fork function returns 0 to the child process that was created and returns the childs ID to the parent process. The two seperate processes are each returned a single value. So think of it more as one return being called on eachthreadprocess.
Why can you kind of cheat compiler this way: ``` const int a = 5; *((int*)&a)=5; // VC/armcc does not complain ``` when above is "abridged" equivalent of this: ``` const int *ptr2const = &a; int *ptr = ptr2const; // as expected error is raised here *ptr = 5; ```
Casting is your way of telling the compiler "I know what I'm doing", so it doesn't complain. Unfortunately, in this instance, you will invoke undefined behaviour.
This question already has answers here:Closed12 years ago. Possible Duplicate:Reason for the Output Hi, Can you please explain me the output of this code snippet? The answer is "d" ``` void main() { short int a=5; clrscr(); printf("%d"+1,a); getch(); } ``` Thanks.
"%d" + 1is a pointer to"d", so in fact you are executingprintf( "d", a );.
In C/C++, the main function receives parameters which are of typechar*. ``` int main(int argc, char* argv[]){ return 0; } ``` argvis an array ofchar*, and points to strings. Where are these string located? Are they on the heap, stack, or somewhere else?
They are compiler magic, and implementation-dependent.
I have a struct like this: ``` struct A { char x[]; }; ``` What does it mean? When I do something like: ``` A a; a.x = "hello"; ``` gcc throws an error saying: ``` error: incompatible types in assignent of 'const char [6]' to 'char [0u]' ```
This is a C99 "flexible array member". See here for gcc specifics:http://www.delorie.com/gnu/docs/gcc/gcc_42.html
What are the Compiler Options & Other mechanism for reducing the static library size? OS : VxWorks Compiler : GCC Language : C
Use-Osto optimise for smaller code size, and leave out-gand any other debug options.
i'm doing some code now and got some problem using restrict keyword. ``` typedef int* pt; int foo(pt a, pt b) { ... /* stuff */ } ``` What if I want to make a and b restricted? The code below failed: ``` typedef int* pt; int foo(pt restrict a, pt restrict b) { ... /* stuff */ } ``` Thanks in advance.
Make sure you're compiling it using the C99 flag for your compiler. Therestrictkeyword doesn't exist in C89 C.
Does anyone know a function/library that I could use to do general FTP functions in a FTP connection? I'd rather have these in C, as that would be extremely easy to add to my current project.
libcurlis probably the best library you can use for that.
I am using c . I have fd1 as a file descriptor, can I call like this twice? ``` main () { .... shutdown(fd1, SHUT_WR); .... shutdown(fd1, SHUT_WR); .... } ``` I personally think it works because fd1 has not been really free yet. Just want somebody to confirm.
You should check the return value of the second call -shutdown(2)probably returns-1- and check the value oferrno(3).
I was looking at some c++ code, and I saw this: ``` int num = *(int *)number; ``` I had never seen this before? it was in a function labeled as such: ``` void *customer(void *number){ } ``` What does that even do? Is there a different way to show this? Thanks, this isn't homework btw I was just confused at what this does?
The (int *) part casts the variable number to a pointer to an int, then the * in front dereferences it to an int.
I'm looking for a runtime memory debugger, capable of showing memory usage (not just leaks) per function or line of C++ code on Linux. I am trying to track down a spike in my program memory usage. I have used Valgrind and Purify and I found that there are are no leaks. I expected that, as after that spike, the memory usage gets back to its expected level for my program. Thanks.
You can use the massif tool from the valgrind pack of tools.
Does OpenSSL have any support for operations in the quadratic extension field (or, alternatively, operations with complex numbers) using the BN API? If not, are there any other open source libraries that do?
You may want to look atPBC. This is a library for computing pairings on some elliptic curves, which implies using field extensions of various degrees, including quadratic extensions for some fields.
I am using c . I have fd1 as a file descriptor, can I call like this twice? ``` main () { .... shutdown(fd1, SHUT_WR); .... shutdown(fd1, SHUT_WR); .... } ``` I personally think it works because fd1 has not been really free yet. Just want somebody to confirm.
You should check the return value of the second call -shutdown(2)probably returns-1- and check the value oferrno(3).
I was looking at some c++ code, and I saw this: ``` int num = *(int *)number; ``` I had never seen this before? it was in a function labeled as such: ``` void *customer(void *number){ } ``` What does that even do? Is there a different way to show this? Thanks, this isn't homework btw I was just confused at what this does?
The (int *) part casts the variable number to a pointer to an int, then the * in front dereferences it to an int.
I'm looking for a runtime memory debugger, capable of showing memory usage (not just leaks) per function or line of C++ code on Linux. I am trying to track down a spike in my program memory usage. I have used Valgrind and Purify and I found that there are are no leaks. I expected that, as after that spike, the memory usage gets back to its expected level for my program. Thanks.
You can use the massif tool from the valgrind pack of tools.
Does OpenSSL have any support for operations in the quadratic extension field (or, alternatively, operations with complex numbers) using the BN API? If not, are there any other open source libraries that do?
You may want to look atPBC. This is a library for computing pairings on some elliptic curves, which implies using field extensions of various degrees, including quadratic extensions for some fields.
What's the counter part of _wfopen? I found that there is fclose related to fopen, but it seems there is no _wfclose.
I would sayfclose(), since you don't actually need anything "wide" in order to close it.
Using only bitwise operators (|, &, ~, ^, >>, <<) and other basic operators like +, -, and !, is it possible to replace the "==" below? ``` int equal(int x, int y) { return x == y; } ```
Remember that anXORis the exactly same asNOT EQUALSandXNORis exactly the same asEQUALS. So, the following will give you exactly what you want: ``` return !(x ^ y); ```