question
stringlengths
24
425
answer
stringlengths
5
405
My scenario is as follows:(C++) In char a[10], the array a[] has elements (numbers) like '1','2','3' etc.... Say a[0] = '1';a[1] = '2';a[2] = '3'; Now a[] is storing 3 characters '1', '2' and '3'.I want to store this into an int as 123 (An integer 123). How to achieve this in C++ ?
a[3] = 0is a must. If your string isn't null-terminated, most methods won't work. After that, it's a simplenumber = atoi(a)
pthread_self()is to get your own thread id. It doesn't seem like you can get the thread id of the thread which spawned you unless it was given to you during spawning. Or is there a way?
No, all threads are equal in POSIX threads, there is no hierarchy. Even the thread that executesmainhas no special role and can be terminated without effecting the others.
in Linux kernel source code, I find below code: ``` h++; pending >>= 1; ``` It is part of__do_softirq(void). But what does ">>=" mean? Why isn't it ">>" as I remember? Thanks!
It simply does ``` pending = pending >>1; ``` In short it divides by 2 an unsigned int. That's the same construct than+=,/=, etc. It's not justpending >>1as you remember because that wouldn't store the result of the shift operation in the variable.
Using (I think) Visual basic / studio I want to make a bar to go at the top of my screen which would display a webpage. Before I start trying to code it, is this concept possible (that the bar would dock at the top of the screen and other windows would change to fit around it.) Thanks - Ryan
Sure, you would probably need to create it as a Windows Shell plugin.
How do I compile and executeRedis ziplist.cas individual executable ? I want to execute ziplist.c main function ONLY.
You can use the following command: ``` gcc -std=c99 -O2 -DZIPLIST_TEST_MAIN ziplist.c zmalloc.c util.c sds.c adlist.c ``` Note: it will use the default system allocator.
pthread_self()is to get your own thread id. It doesn't seem like you can get the thread id of the thread which spawned you unless it was given to you during spawning. Or is there a way?
No, all threads are equal in POSIX threads, there is no hierarchy. Even the thread that executesmainhas no special role and can be terminated without effecting the others.
in Linux kernel source code, I find below code: ``` h++; pending >>= 1; ``` It is part of__do_softirq(void). But what does ">>=" mean? Why isn't it ">>" as I remember? Thanks!
It simply does ``` pending = pending >>1; ``` In short it divides by 2 an unsigned int. That's the same construct than+=,/=, etc. It's not justpending >>1as you remember because that wouldn't store the result of the shift operation in the variable.
Using (I think) Visual basic / studio I want to make a bar to go at the top of my screen which would display a webpage. Before I start trying to code it, is this concept possible (that the bar would dock at the top of the screen and other windows would change to fit around it.) Thanks - Ryan
Sure, you would probably need to create it as a Windows Shell plugin.
How do I compile and executeRedis ziplist.cas individual executable ? I want to execute ziplist.c main function ONLY.
You can use the following command: ``` gcc -std=c99 -O2 -DZIPLIST_TEST_MAIN ziplist.c zmalloc.c util.c sds.c adlist.c ``` Note: it will use the default system allocator.
I am using the GCC compiler but I want the to code the actually run after compilation. Is there a flag I can use for this? Right now I am just doing ``` gcc code.c ``` There is no code.exe being generated...
The file created by default is called a.out. If you want to name it code.exe, the correct line should begcc -o code.exe code.c
I've an array of fixed size inC. There I might have any number (less than the array size) of useful element. Now I need only my useful element. So I'm thinking of using anend of arraymarker for integer array. First of all a) Is this possible? b) If possible, How?
I would take a slightly different approach ``` struct IntArray { int data[N]; int size; // <-- use this to keep track of the size. } ```
I am using the GCC compiler but I want the to code the actually run after compilation. Is there a flag I can use for this? Right now I am just doing ``` gcc code.c ``` There is no code.exe being generated...
The file created by default is called a.out. If you want to name it code.exe, the correct line should begcc -o code.exe code.c
I've an array of fixed size inC. There I might have any number (less than the array size) of useful element. Now I need only my useful element. So I'm thinking of using anend of arraymarker for integer array. First of all a) Is this possible? b) If possible, How?
I would take a slightly different approach ``` struct IntArray { int data[N]; int size; // <-- use this to keep track of the size. } ```
I've an array of fixed size inC. There I might have any number (less than the array size) of useful element. Now I need only my useful element. So I'm thinking of using anend of arraymarker for integer array. First of all a) Is this possible? b) If possible, How?
I would take a slightly different approach ``` struct IntArray { int data[N]; int size; // <-- use this to keep track of the size. } ```
I am doing a CBIR system as an assignment.There are 100 .bmp files,but they have different size,how to re-size them to a same size? Thanks.
Have a look at theCImg Library, it's quite easy to use. You can load your bitmap file then use one of theresizefunction.
I am confused about the evaluation time ofsizeofoperator.When does the sizeof operator get evaluated? Does its evaluation time (compile-time or runtime) depend on the language (C? C++?)? Can we usesizeofin case of objects created at runtime in C++?
In almost all cases,sizeofis evaluated based on static type information (at compile-time, basically). One exception (the only one, I think) is in the case of C99's variable-length arrays (VLAs).
Does the stack of a thread/process make seperate copy of static function/method or is it shared.if it is shared where it is kept/stored and how does the mechanism works in C. Rgds, Softy
Static function is used to limit the scope of the function within file. As it is a function(code) it goes to text(code) segment. You can understand in details from following article http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory
Does the stack of a thread/process make seperate copy of static function/method or is it shared.if it is shared where it is kept/stored and how does the mechanism works in C. Rgds, Softy
Static function is used to limit the scope of the function within file. As it is a function(code) it goes to text(code) segment. You can understand in details from following article http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory
How do I do the opposite of this: ``` while((*i2s) & (1<<19)) usleep(10); ``` I want to keep sleeping while the 19th bit is 0.
``` while(((*i2s) & (1<<19)) == 0) usleep(10); ``` of course.
I'm sure others have already asked this, but is it possible to insert an element into the next available index of an array without using a for-loop to find that index first? Almost like a list.add() function but for arrays in C.
no, you will have to loop through the array.
Commands like sftp work in a way that it's not possible to pipe in user input (ex:password etc...) Q1: How does sftp achieve this? Q2: How do programs like expect get around this restriction?
Requires TTY to be connected for input.expect et al. allocate PTTYs to get around this.
I want to create a HTTP request from a specific port using C on a Linux machine. There islibcurlbut I'm not sure if you can specify the interface. Is it possible ? Many thanks :).
Yes it is. Look into the optionsCURLOPT_INTERFACEandCURLOPT_LOCALPORT.
I can embed hexadecimal values in Python-Strings like this:\xe5abcdefghijklmnoqrstuvqxy\xfdz!\x18\xfejk Is this possible with C?
Yes, using the same notation. ``` printf("\x41\x42\x43\n"); ```
I have to multiply 2 large integer numbers, every one is 80+ digits. What is the general approach for such kind of tasks?
You will have to use a large integer library. There are some open source ones listed on Wikipedia's Arbitrary Precision arithmetic pagehere
``` char imei_temp[14] = {0, }; strcpy(imei_temp, "00000000000000"); ``` According to my understanding this is valid code. But Klocwork is saying Buffer overflow, array index of 'imei_temp' may be out of bounds. Array 'imei_temp' of size 14 may use index value(s) 0..14
It's a buffer overflow because your buffer is 14 bytes, but you are writing 15 bytes to it: 14 ascii "0"'s, and a null byte at the end.
I can embed hexadecimal values in Python-Strings like this:\xe5abcdefghijklmnoqrstuvqxy\xfdz!\x18\xfejk Is this possible with C?
Yes, using the same notation. ``` printf("\x41\x42\x43\n"); ```
I have to multiply 2 large integer numbers, every one is 80+ digits. What is the general approach for such kind of tasks?
You will have to use a large integer library. There are some open source ones listed on Wikipedia's Arbitrary Precision arithmetic pagehere
``` char imei_temp[14] = {0, }; strcpy(imei_temp, "00000000000000"); ``` According to my understanding this is valid code. But Klocwork is saying Buffer overflow, array index of 'imei_temp' may be out of bounds. Array 'imei_temp' of size 14 may use index value(s) 0..14
It's a buffer overflow because your buffer is 14 bytes, but you are writing 15 bytes to it: 14 ascii "0"'s, and a null byte at the end.
I'm doing a project with a lot of calculation and i got an idea is throw pieces of work to GPU, but i wonder whether could we retrieve results from GLSL, if it is posible, how?
GLSL does not provide outputs besides what is placed in the frame buffer. To program a GPU and get results more conveniently, useCUDA(NVidia only) orOpenCL(cross-platform).
If I omit the operators from statement, something like this:while(foo)will the compiler turn it inwhile(foo != NULL || *foo != '\0' || foo != 0)orwhile(!foo)or something like this? how to it is really done?
while (condition)just checks forconditionbeing non-zero. Therefore these two are equivalent: ``` while (foo) while (foo != 0) ```
I have an array with a size that I dont know(mostly a size of a 10), that most of it has 1's and 2's, but sometimes 3's and 4's... I cant buble sort, because the order is importhan, but other then that, I can do everything Thanks :)
Iterate over the array until you hit your break condition. While iterating (use thefororwhileloop), remember the highest value so far and compare against current.
There is a file of 1 GB contains a single string of characters. As the string is very large it can't be loaded completely to memory. What is the best way to reverse this string?
load blocks into memory, iterate through them in reverse while writing them out in order. pseudocode: ``` load_block(buffer, 4mb, end of file); // Load a 4mb block from the end for (i = 4mb; i>=0; i--) { write(buffer[i],1); // Write it out in reverse } ```
i'm writing an app that needs a calculation support (Fun project). However, is there a way to enter input data to the interactive console in BC from C#, and then read the data from the console with C#? I have tried to use dllexport in the c source, but the code is confusing me.
The usual way to interact with prewritten console applications in c# is to useProcess.Startand then redirectStandardInputandStandardOutput.
Is there any control that can be used for drawing a diagram like this in winapi32 controles? in not do you have any idea how can I draw one? (something like this!)
You will find third party chart control for the Windows APIs -http://www.gigasoft.com/graphinglibrary.htmlhttp://www.codeproject.com/Articles/14330/Custom-Control-Graph-and-Process-Bar Or you can draw the line graph yourself using the GDI functionsLineToandMoveTo.
i'm writing an app that needs a calculation support (Fun project). However, is there a way to enter input data to the interactive console in BC from C#, and then read the data from the console with C#? I have tried to use dllexport in the c source, but the code is confusing me.
The usual way to interact with prewritten console applications in c# is to useProcess.Startand then redirectStandardInputandStandardOutput.
Is there any control that can be used for drawing a diagram like this in winapi32 controles? in not do you have any idea how can I draw one? (something like this!)
You will find third party chart control for the Windows APIs -http://www.gigasoft.com/graphinglibrary.htmlhttp://www.codeproject.com/Articles/14330/Custom-Control-Graph-and-Process-Bar Or you can draw the line graph yourself using the GDI functionsLineToandMoveTo.
Is there a function or any other way to calculate in C the logarithm of basex, wherexis an integer variable of my program?
C doesn't provide functions to compute logarithms of any bases other thaneor10. So just use math: ``` logarithm of x base b = log(x)/log(b) ``` If you'll be doing the logarithms over the same base repeatedly, you can precompute1/log(b).I wouldn't rely on the compiler being able to do this optimization for you.
Is there any way to clear parser buffers before callingYYACCEPTinyacc. If i do not clear buffer it causes some problems when i callyyparsefor the second time. Also note that I am using some global variables, so cannot use reentrant parser. Thanks in advance !!
There sure is. Seethis sectionof the flex manual. Specifically, callYY_FLUSH_BUFFERbefore callingyyparse.
Will a thread stop if I send it SIGTSTP signal? Or in other words will it behave like process on SIGTSTP and SIGCONT? Thanks in advance.
From `man 3p pthread_kill: Note that pthread_kill() only causes the signal to be handled in the context of the given thread;the signal action (termination or stopping) affects the process as a whole. So I'd say that you will stop the whole process, not just the thread.
Doesa && (b = 5/a)assign5/atob(for nonzeroa)? My friend says it doesn't, but I'm confused why it wouldn't.
Your friend is wrong. For nonzeroa, the statementa && (b = 5/a)will assign the value5/atob. Ifa == 0, then the conditional will short circuit and the assignment will not occur.
I would like to store all paths to headers in separate file. I'm going to generate file with paths dynamically, to avoid re-creating Makefile whenever paths change. Is that possible?
Yes, you can generate the file, let's call itpaths.inc, so it looks like, for example: ``` INCLUDEPATH=path1:path2 ``` and then include the file in your mainMakefile ``` include paths.inc ``` and use the variable defined in it:${INCLUDEPATH}
What is the linux API to query the status of a thread, like thetop -Hcommand can do? I do not need portability, it just has to work on modern x86[_64] linux. I do not want to only know if the thread is alive or terminated. I need to know if it's sleeping also.
As far as I knowtopreads its information from/proc, on Linux at least. Update: Fortop's sources you might like to read here:Procps - The /proc file system utilities
The download page for cmake only shows a 32 bit installer for windows. Any idea how to install it on 64 windows systems.
There is really no reason for a 64bit native CMake. CMake is only building theconfiguration, so you can use it to build configurations for 64bit software, even with the 32bit version. That being said, if you truly want a 64bit native version, you could always download the source and compile it. There is no 64bit installer, however.
I have an array which is sorted in descending order, with no duplicates. Can I perform binary search on it using bsearch function in libc ? To do this, do I need to alter the compare function that I am passing to it ? Thanks
Yes, you can usebsearch. You will need to make sure yourcomparefunction agrees with the sort order of your array. In your case that might mean logically inverting the normal ascending/equal/descending order.
How can one tell, given avoid *pointer, what is the size of a block allocated on this given address (previously allocated usingmalloc; in Linux and Windows)? I hope both systems surely store this kind of information somewhere. That is, alternative ofmalloc_sizewhich exists on OSX/Darwin. Using gcc/mingw if it helps.
On Windows, things that use the MS CRT can use_msize, on Linux you could trymalloc_usable_size...
Under Windows I use MultiByteToWideChar(CP_ACP, ...) and WideCharToMultiByte(CP_UTF8, ...) for the conversion. How do I do the same thing under OS X and Linux? I tried mbstowcs/wcstombs but the resulting char* is not UTF-8.
Look intoiconv(3). that's the api you want. You'll need-liconv.
if possible then how to return more than one value. It can not be because of return is done through Accumulator in controller or CPU. Is this is the correct reason?
Because that's how the language is defined. There is no fundamental reason; other languages can return multiple values (e.g. Matlab). As a "workaround", you can return a struct that contains multiple fields.
According to K&R C section 1.6, acharis a type of integer. So why do we need%c. And why can't we use%dfor everything?
Because%dwill print the numeric character code of thechar: ``` printf("%d", 'a'); ``` prints97(on an ASCII system), while ``` printf("%c", 'a'); ``` printsa.
What is the difference between_m256iand_m256dand_m256? andWhat is the difference between_m128iand_m128dand_m128?
Rule of thumb: anisuffix is used for allintegervector types,dis fordouble precisionfloating point vector types, and when there is no suffix it's forsingle precisionfloating point vector types.
Using Eclipse, working with (ANSI) C language, is there any way to view the values that pointers are pointing on from debug? Thanks
I haven't used Eclipse in years, but isn't there a "watch" window, where you can add variables to watch? In that case you should be able to just put*pointerin there.
Under Windows I use MultiByteToWideChar(CP_ACP, ...) and WideCharToMultiByte(CP_UTF8, ...) for the conversion. How do I do the same thing under OS X and Linux? I tried mbstowcs/wcstombs but the resulting char* is not UTF-8.
Look intoiconv(3). that's the api you want. You'll need-liconv.
if possible then how to return more than one value. It can not be because of return is done through Accumulator in controller or CPU. Is this is the correct reason?
Because that's how the language is defined. There is no fundamental reason; other languages can return multiple values (e.g. Matlab). As a "workaround", you can return a struct that contains multiple fields.
According to K&R C section 1.6, acharis a type of integer. So why do we need%c. And why can't we use%dfor everything?
Because%dwill print the numeric character code of thechar: ``` printf("%d", 'a'); ``` prints97(on an ASCII system), while ``` printf("%c", 'a'); ``` printsa.
What is the difference between_m256iand_m256dand_m256? andWhat is the difference between_m128iand_m128dand_m128?
Rule of thumb: anisuffix is used for allintegervector types,dis fordouble precisionfloating point vector types, and when there is no suffix it's forsingle precisionfloating point vector types.
Using Eclipse, working with (ANSI) C language, is there any way to view the values that pointers are pointing on from debug? Thanks
I haven't used Eclipse in years, but isn't there a "watch" window, where you can add variables to watch? In that case you should be able to just put*pointerin there.
How can I dump all the global variables and the address offsets in my executable? This is on os x, app developed with xcode compiled with gcc. Thank you
If Compiled to Mach-O Either useotoolor thecctools. If Compiled to ELF You should be able to do this withobjdumpand/orreadelf. I don't have a *nix system at hand here, butobjdump -s -j .datashould be getting you rather close enough.
Is there any way to know / warn if a global variable is uninitialized with gcc ? I got it for local/ atomic variables “-Wuninitialized”
No!Global and static variables are initialized implicitly if your code doesn't do it explicitly as mandated by the C standard.In short, global and static variables are never left uninitialized.
I understand how to create astructon the heap usingmalloc. Was looking for some documentation regarding creating astructin C on the stack but all docs. seem to talk about struct creation on heap only.
The same way you declare any variable on the stack: ``` struct my_struct {...}; int main(int argc, char **argv) { struct my_struct my_variable; // Declare struct on stack . . . } ```
Suppose I have the following structs: ``` struct A{ int a; } a; struct B{ A a; int b; } b; ``` how to check ifbis of typeBor ifbis of the typeA?
Do you mean at runtime, given avoid *that points to one or the other? Unfortunately, this is not possible; C doesn't have any kind of runtime type information mechanism.
How can I get the current total allocated memory so far (in a Linux process inC/C++ (gcc))?
Try parsing/proc/self/mapsor/proc/$PID/maps. Look for a line marked[heap].
When I sendWM_SETREDRAWto disable redraw for a window, how do I "restore" the previous state when I'm done? What's the proper way to send this message?
You can'trestore the previous state, as there is no way to access the current state. There is noWM_GETREDRAW. Once you are done you sendWM_SETREDRAWagain withTRUEas an argument this time, and if anyone else had set redraw toFALSEon an outer scope then well.. that's bad for them..
I have a number like this:int num = 36729;and I want to get the number of digits that compose the number (in this case 5 digits). How can I do this?
Use this formula: ``` if(num) return floor(log10(abs((double) num)) + 1); return 1; ```
Indouble (*foo)[2]what does the[2]represent? And how would I convert an array as such to an array of float* in C?
``` double (*foo)[2] ``` foois a pointer to an array of twodoubleelements. For example: ``` double bla[2]; double (*foo)[2] = &bla; ```
I have an array of int and i have to initialize this array with the value -1. For now i use this loop: ``` int i; int myArray[10]; for(i = 0; i < 10; i++) myArray[i] = -1; ``` There are faster ways?
The quickest way I know for the value-1(or0) ismemset: ``` int v[10]; memset(v, -1, 10 * sizeof(int)); ``` Anyway you can optimize the loop in this way: ``` int i; for(i = 10; i--;) v[i] = -1; ```
I have to write a C program to convert XML file to WBXML format, without using external conversion library. Is it possible? I have created the XML file in C and now want to convert it into WBXML file.
You want to know if it is possible? - Yes. You want to know how? - check the implementation of one of theexternal libraries. I'm sure you can get an idea if you browse the source code.
I often see something likeattributein error messages. What is this? Are there any similar things like thisattribute? Can anyone give me a detailed explanation?
It is aGCC extensionwhich allows a developer to attach characteristics to function declarations to allow the compiler to perform more error checking. Detailed Explanation also foundhereandhere. A set of GCC extensions for C can be foundhere.
How do I get the key codes so I can process arrow, pageUp, pageDown, etc, keys using simple C or C++? I can get the regular keys, I do not know how to get these special keys.
Ncurses should be able to handle that. There is lots of tutorials out there
When I attach gdb to a process that uses many source files, such as PHP, sometimes I want to set a breakpoint on line x of file y. How do I specify the file for gdb?
It's as simple as: ``` b filename.c:XYZ ``` Seethe documentationfor more info.
How do I get the key codes so I can process arrow, pageUp, pageDown, etc, keys using simple C or C++? I can get the regular keys, I do not know how to get these special keys.
Ncurses should be able to handle that. There is lots of tutorials out there
someone please tell me which one of the following is more fast and why ?? ``` int add(int a, int b){ return a+b; } ``` OR ``` void add(int a, int *b){ *b = a+(*b); } ```
Chances are functions areinlinedand both result in the same generated code.
What kind of API or algorithm is normally used to generate session ids? For something like an online game? Thanks
You can useUUID-v4. Implementations are available in pretty much any language. Here is one for C++: http://sourceforge.net/projects/ooid/
I saw the following code in CCTL (~line 330)https://github.com/jobytaffey/cctl/blob/master/cctl/main.c ``` switch(page) { // ... ack: cons_putc(0); } ``` What is theack:section for? It looks like same asdefault:to me. I can't find it in the SDCC docs either. Is this something in C spec? Thank you
It's not a C keyword; it's just a label. Note the correspondinggotostatements.
This question already has answers here:Closed11 years ago. Possible Duplicate:Why do these two pointer subtractions give different results? ``` char arr[] = "stackoverflow"; char *p1 = arr; char *p2 = arr + 3; printf("%d", (int*)p2 - (int*)p1); ``` it's answer is 0..Can you explain why is it so ?
Becausep2 - p1is< sizeof (int). So(int *) p2 - (int *) p1 == 0, the number ofintelements between the two pointers.
Do I need to include a library? Can anyone please elaborate in it? I know is used to get the process id of the current task where is being called from But I want to printk something with current->pid printk("My current process id/pid is %d\n", current->pid); ...and is giving me an error error: dereferencing pointer to incomplete type
You're looking for#include <linux/sched.h>. That's wheretask_structis declared.
I'm writing code that depends on whether or not a header file is included. If the file is included, I want certain added functionality. Is there any way to do this, perhaps with an #if? Using C btw
Just#definea symbol in that header and use#ifdeflater on. ``` header.h #define HAVE_IPV6 some_file.c #ifdef HAVE_IPV6 /* code */ #endif ```
I saw the following code in CCTL (~line 330)https://github.com/jobytaffey/cctl/blob/master/cctl/main.c ``` switch(page) { // ... ack: cons_putc(0); } ``` What is theack:section for? It looks like same asdefault:to me. I can't find it in the SDCC docs either. Is this something in C spec? Thank you
It's not a C keyword; it's just a label. Note the correspondinggotostatements.
This question already has answers here:Closed11 years ago. Possible Duplicate:Why do these two pointer subtractions give different results? ``` char arr[] = "stackoverflow"; char *p1 = arr; char *p2 = arr + 3; printf("%d", (int*)p2 - (int*)p1); ``` it's answer is 0..Can you explain why is it so ?
Becausep2 - p1is< sizeof (int). So(int *) p2 - (int *) p1 == 0, the number ofintelements between the two pointers.
Do I need to include a library? Can anyone please elaborate in it? I know is used to get the process id of the current task where is being called from But I want to printk something with current->pid printk("My current process id/pid is %d\n", current->pid); ...and is giving me an error error: dereferencing pointer to incomplete type
You're looking for#include <linux/sched.h>. That's wheretask_structis declared.
I'm writing code that depends on whether or not a header file is included. If the file is included, I want certain added functionality. Is there any way to do this, perhaps with an #if? Using C btw
Just#definea symbol in that header and use#ifdeflater on. ``` header.h #define HAVE_IPV6 some_file.c #ifdef HAVE_IPV6 /* code */ #endif ```
I have a call likeclock_gettime(CLOCK_REALTIME), does it handle leap seconds? If not, what changes are required? Working on Solaris.
If your Unix system is synchronized with NTP, chances are that it handles leap seconds. See this article for more information:NTP Leap Second.
I have very simple xml ``` <root> <node>some value</node> </root> ``` How can I get the serialized HTML fragment, using libxml and C. I mean same as you can get usingouterHTMLin JS (document.getElementsByTagName("node")[0].outerHTML).
You have to usexmlNodeDump. Or if you want to print node out to file/stdout, then usexmlElemDump
As the title said, I have a task that I need to read data from excel files. I'm wondering how to implement it in pure C, not C++ or C#. Btw, I need to write and test the program in Linux but others may use the code in Windows, which means my code has to be OS independent. Thank you.
Check outhttp://xlslib.sourceforge.net/
If I use macros in my C code, such as ``` #define var 10 ``` then where exactly are the stored in the space allocated to the process by the kernel? In heap or BSS or global data? Or is it just a text replacement for var in one of the compiler passes?
Yes.the last one just a text replacement It is performed by a preprocessing pass. Some good details can be foundhere
Is the stack allocated at runtime or compile time?Example: ``` void main() { int x; scanf("%d", &x); int arr[x]; } ```
Stack isallocatedat runtime; layout of each stack frame, however, is decided at compile time, except for variable-size arrays.
When I want to work with big and small digits how must I sum / compare values in C? ``` #include <stdio.h> #include <math.h> int main(void) { if (1.0 + (1/pow (10,50)) == 1.0) printf("true"); else printf("false"); return 0; } ``` how to make it to return false?
You can't make it return false with standard C types. You'll need to use a high-precision floating point library.
I'm curious because the man page of connect(2) is pretty short and it takes a struct sockaddr* which is normally cast anyways..
sockaddr_inandin_addraren't even similar. There's no way that would work. There different because more than an address is usually needed. For example, a port number is needed to establish connect a IP socket.
DigiFlow is used for image processing for fluid dynamics experiments -DigiFlow website. There is a console within the program which is used for writing macros. Some example code: ``` function do_this(variable) {variable += 2}; output := do_this(5); ``` (output = 7 after running this.)
From assignment and function declaration I'd say it looks like Google'sgo language. Pascal might be another choice.
This question already has an answer here:Closed11 years ago. Possible Duplicate:What is the C Equivalent of Python's pack(“<I”, 0) How can I replicate the code in Python: ``` from struct import pack string = pack("<I", 0x11111111) print string ``` in C? From what I understand \x11 is a nonprintable character so...?
``` const char *string = "\x11\x11\x11\x11"; puts(string); ```
This question already has an answer here:Closed11 years ago. Possible Duplicate:What is the C Equivalent of Python's pack(“<I”, 0) How can I replicate the code in Python: ``` from struct import pack string = pack("<I", 0x11111111) print string ``` in C? From what I understand \x11 is a nonprintable character so...?
``` const char *string = "\x11\x11\x11\x11"; puts(string); ```
Given: ``` int a[N]; int *p; ``` why doesa-pwork yeta+pdoes not with error: "invalid operands to binary +".
Thedifferencebetween two pointers is meaningful, i.e. it is the number of elements between the two pointers (provided that they both lie within the same array). Addingtwo pointers makes no sense though (how would you interpret it ?).
I have a repository. I don't want to checkout the whole repository but just one folder inside it. I don't remember the folder names, so I want to see them. Is there a command in svn which can show all the folder names in the root directory of the repository.
Have you triedsvn ls http://repo.url/here?
Given: ``` int a[N]; int *p; ``` why doesa-pwork yeta+pdoes not with error: "invalid operands to binary +".
Thedifferencebetween two pointers is meaningful, i.e. it is the number of elements between the two pointers (provided that they both lie within the same array). Addingtwo pointers makes no sense though (how would you interpret it ?).
I have a repository. I don't want to checkout the whole repository but just one folder inside it. I don't remember the folder names, so I want to see them. Is there a command in svn which can show all the folder names in the root directory of the repository.
Have you triedsvn ls http://repo.url/here?
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago. What is the meaning of "f" in C's printf?
Thefinprintfstands forformatted, its used for printing with formatted output.
How could I go about writing a Haskell library to provide input functionality similar to that provided by SDL or GLFW? Specifically, how would I go about grabbing device events (e.g. mouse, keyboard, joystick) and system events (e.g. quit, resize, window move, focus).
Make FFI bindings to the primitives provided by the platform (or library) you're building on.Use these primitives to implement higher level abstractions.
I want creat a C program for Unix that can porcess the Regular Expression,like a simple Perl interpreter. Do I have to personally write an regexp engine?
http://www.gnu.org/software/libc/manual/html_node/Regular-Expressions.html You might like to look for a library with it already coded. C uses librarys to allow you to include other peoples code into your work. I assume there are many regular expression librarys for you to use already to go!
Embarrassingly basic question.sudo apt-get install libmemcached6- where do the .h's and .o's or .so's live in a typical install on a Linux machine (Ubuntu)? And, how do I make sure g++ can pick them up?
They go to /usr/include and /usr/lib. If you use the -l option (for the libraries) it should find them from these standard places. If you include using<file.h>it should also get it from the right place.
There is a function I have written in C that I would like to use in the debugger to send commands to a javascript engine. Since this function is not used directly in code the linker strips this symbol. Is there a way to mark a particular function to not be stripped?
Found it! http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/XcodeBuildSystem/500-Linking/bs_linking.html declaration should have ``` __attribute__((used)) ```
There is a function I have written in C that I would like to use in the debugger to send commands to a javascript engine. Since this function is not used directly in code the linker strips this symbol. Is there a way to mark a particular function to not be stripped?
Found it! http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/XcodeBuildSystem/500-Linking/bs_linking.html declaration should have ``` __attribute__((used)) ```
Namely code similar to this, making the printout undefined. ``` int a=41; a++ & printf("%d\n", a); ``` I don't know what exactly this operation is called.
The problem is that it is not specified which is evaluated first, theprintfor thea++, and since one has a side effect on the other (you either readathen write it then read it again, or read it then read it then write it), you get undefined behaviour.