question
stringlengths
24
425
answer
stringlengths
5
405
I want to move a Window (HWND) in a second monitor. The thing is that I tried many things like double the resolution or putting negative values and it never was able to put the window on my second monitor. Any clue of how to do that in C/C++/c#
Screen and the Form.StartPosition should get you there. See the first answer to this post (for C#/WinForms solution):How do I ensure a form displays on the "additional" monitor in a dual monitor scenario?
I'm making a program and one of the things it needs to do is transfer files. I would like to be able to check before I start moving files if the File system supports files of size X. What is the best way of going about this?
Go on with using a function likeftruncateto create a file of the desired size in advance, before the moving, and do the appropriate error-handling in case it fails.
I would like to know if there is any kind of regular expression expansion within the compiler(GCC) pre processor. Basically more flexible code generation macros. If there is not a way, how do you suggest i accomplish the same result
The C preprocessor can't do that. You might want to use a template processor (for instanceMustachebut there are many others) that generates what you need before passing it to the compiler.
Can I do code such: ``` char *p; p = User_input; ``` Is it possible to assign a string topat runtime?
Sure you can, but there is nostringin c, I think you meanchar *, like ``` char *user_input = malloc(128); scanf("%s", userinput); p = user_input; ```
I would like to list all Lotus Notes installations on my computer. How can I do that by using C and Win32 API?
You may have an easier time searching the registry for Lotus Notes keys. One of the keys tells the version installed
I want GtkEntryCompletion to get data from additional source (function or another model, no matter) when there's no match in models data. Is that possible?
Make a custom class that implements theGtkTreeModelinterface, and retrieves data preferentially from one model and then another if not found.
Does anyone know how to print out memory addresses of UNIX application's memory using C? I need to print out those information of addresses when I run my code, for instance 'the number of pages of physical memory' The output i'm looking for this example is something like... ``` Number of pages: 384285 ``` Thank you
``` char buf[40]; sprintf(buf, "exec cat /proc/%d/status", getpid()); system(buf); ```
I have printer HP LaserJet P2015 Series configured in the lan and i have enabled the snmp access in the printer. Need a way to get output for snmp-mib's ? via c , c++ or java
For Java, take a look at thesnmp4jproject. For C, take a look at theNet-SNMPproject. Both projects are open source and provide SNMP client APIs.
I think the title is self explanatory. I am making a program and I was wondering what I should use of the two and why.
argpmay be more flexible / powerful / etc, butgetoptis part of the POSIX standard. Thats a choice you've to make based on whether you expect your program to be portable.
Is there a way in gcc or clang (or any other compiler) to spit information about whether a struct has holes (memory alignment - wise) in it ? Thank you. ps: If there is another way to do it, please do inform me.
You can usepaholeto output information about holes in structures and optionally attempt packing them. You may want to read"Poke-a-hole and friends"andthe pahole announcementfor more information
am developing one dictionary for mac os 10.6. Am not able to locate glib.h. can i get this as a library or framework. am confused very much. please give me your valuable solution. Note: i want to use GSList from glib
Install it usingMacPortsor download the source code and install manually. Or if you're developing a cocoa aplication I'm sure the framework has it's own list structures, it would be better to use the native ones.
Is there some Linux analog of windows functionGetAsyncKeyState()? Or maybe there exists some asynchronous function which returns - Does keyboard buffer empty or not ? Thanks.
The key question here is: For which abstraction? X windows, ncurses or stdio? Linux isn't as simple and monolithic as Windows is. For stdio (plain old stdin/stdout text program)fgetc_unlockeddoes the trick.
I am trying to record a video in OpenCV from a stream such as a webcam with audio. I am currently writing the application to use DirectShow to grab data from the stream and to pass that data into anIplImage*. This is great for creating the video file, but what if I would like to include audio? Do I have to use another library to write out the small amount of audio information? Any help is greatly appreciated.
No, it is not a purpose of OpenCV library.
Is there some Linux analog of windows functionGetAsyncKeyState()? Or maybe there exists some asynchronous function which returns - Does keyboard buffer empty or not ? Thanks.
The key question here is: For which abstraction? X windows, ncurses or stdio? Linux isn't as simple and monolithic as Windows is. For stdio (plain old stdin/stdout text program)fgetc_unlockeddoes the trick.
I am trying to record a video in OpenCV from a stream such as a webcam with audio. I am currently writing the application to use DirectShow to grab data from the stream and to pass that data into anIplImage*. This is great for creating the video file, but what if I would like to include audio? Do I have to use another library to write out the small amount of audio information? Any help is greatly appreciated.
No, it is not a purpose of OpenCV library.
I'm looking for an IDE that supports a (Visual Studio's) Edit and continue -like feature. I know Netbeans has it for Java (called hotswapping, Fix and continue), but can not find anything about an implementation for C/C++ for Linux systems. Any help would be very much appreciated.
To the best of my knowledge, this feature is not available in the GCC toolchain. The closest you'll get is the gdb's rewind, but that's not the same.
I have the following piece of code in C: ``` char a[55] = "hello"; size_t length = strlen(a); char b[length]; strncpy(b,a,length); size_t length2 = strlen(b); printf("%d\n", length); // output = 5 printf("%d\n", length2); // output = 8 ``` Why is this the case?
it has to be 'b [length +1]' strlen does not include the null character in the end of c strings.
In C why is it legal to do ``` char * str = "Hello"; ``` but illegal to do ``` int * arr = {0,1,2,3}; ```
I guess that's just how initializers work in C. However, you can do: ``` int *v = (int[]){1, 2, 3}; /* C99. */ ```
I am trying to get a C string of the owner and group of a file, After I do astat()I get the user ID and group ID, but how do I get the name?
You can usegetgrgid()to get the group name andgetpwuid()to get the user name: ``` #include <pwd.h> #include <grp.h> /* ... */ struct group *grp; struct passwd *pwd; grp = getgrgid(gid); printf("group: %s\n", grp->gr_name); pwd = getpwuid(uid); printf("username: %s\n", pwd->pw_name); ```
I am having trouble with my code, and I can not solve .... the code snippet where the error is reported: ``` static FILE *debugOut = stderr; static FILE *infoOut = stdout; ``` The error that the gcc return is: ``` initializer element is not constant ```
try doing it in main for example: ``` static FILE *debugOut; static FILE *infoOut; main(){ debugOut = stderr; infoOut = stdout; } ```
I'm looking for an IDE that supports a (Visual Studio's) Edit and continue -like feature. I know Netbeans has it for Java (called hotswapping, Fix and continue), but can not find anything about an implementation for C/C++ for Linux systems. Any help would be very much appreciated.
To the best of my knowledge, this feature is not available in the GCC toolchain. The closest you'll get is the gdb's rewind, but that's not the same.
I have the following piece of code in C: ``` char a[55] = "hello"; size_t length = strlen(a); char b[length]; strncpy(b,a,length); size_t length2 = strlen(b); printf("%d\n", length); // output = 5 printf("%d\n", length2); // output = 8 ``` Why is this the case?
it has to be 'b [length +1]' strlen does not include the null character in the end of c strings.
In C why is it legal to do ``` char * str = "Hello"; ``` but illegal to do ``` int * arr = {0,1,2,3}; ```
I guess that's just how initializers work in C. However, you can do: ``` int *v = (int[]){1, 2, 3}; /* C99. */ ```
I am trying to get a C string of the owner and group of a file, After I do astat()I get the user ID and group ID, but how do I get the name?
You can usegetgrgid()to get the group name andgetpwuid()to get the user name: ``` #include <pwd.h> #include <grp.h> /* ... */ struct group *grp; struct passwd *pwd; grp = getgrgid(gid); printf("group: %s\n", grp->gr_name); pwd = getpwuid(uid); printf("username: %s\n", pwd->pw_name); ```
I am having trouble with my code, and I can not solve .... the code snippet where the error is reported: ``` static FILE *debugOut = stderr; static FILE *infoOut = stdout; ``` The error that the gcc return is: ``` initializer element is not constant ```
try doing it in main for example: ``` static FILE *debugOut; static FILE *infoOut; main(){ debugOut = stderr; infoOut = stdout; } ```
How to define local static variables (that keeps its value between function calls) that are not shared among different threads? I am looking for an answer both in C and C++
on Windows using Windows API:TlsAlloc()/TlsSetValue()/TlsGetValue() on Windows using compiler intrinsic: use_declspec(thread) on Linux (other POSIX???) :get_thread_area()and related
I am writing daemon application for Debian Sid. It works perfectly most of the times, but dies silently after i put my laptop to suspend (or hibernate). So i have a couple of questions: What should I Google for solutions?Maybe, you have any ideas what is going on?
Trystrace-ing the daemon to see what is the reason it dies silently. Generally, suspend/hibernate alone should have no effect on user processes.
How to define local static variables (that keeps its value between function calls) that are not shared among different threads? I am looking for an answer both in C and C++
on Windows using Windows API:TlsAlloc()/TlsSetValue()/TlsGetValue() on Windows using compiler intrinsic: use_declspec(thread) on Linux (other POSIX???) :get_thread_area()and related
What that declaration means in C ? ``` void help_me (char *, char *); ``` I'm newbie, but I know about pointers. Seems like this is something different ?
This declaration says thathelp_meis a function taking two pointers tochar(for example, two strings). For a function prototype declaration the variable names are optional:void help_me (char *, char *);andvoid help_me (char * foo, char * bar);are equivalent.
I've got a method signature: ``` void word_not(lc3_word_t *R, lc3_word_t *A) ``` I need to take the contents of *A and copy them into *R. How do I do this? I've tried assignment *R = *A; but my compiler complains. Any ideas?
``` memcpy(R, A, sizeof(lc3_word_t)); ``` memcpycopies a specific number of bytes from A to R. This assumes that this makes sense for the structs of type lc3_word_t that R points to allocated space.
What is the difference betweenxmalloc()andmalloc()for memory allocation?Is there any pro of usingxmalloc()?
xmalloc()is a non-standard function that has the mottosucceed or die. If it fails to allocate memory, it will terminate your program and print an error message tostderr. The allocation itself is no different; only the behaviour in the case that no memory could be allocated is different. Usemalloc(), since it's more friendly and standard.
I study C. Digging in some C source code where I found that line. I have read about pointers, but I did not see such an example. ``` char *uppercase (char *s); ``` What that mean ?
It's a declaration of a function that takes a char pointer and returns a char pointer.
When writing characters to an array from a stream, is there a way to make the length of the array the exact number of characters if the size of the stream is unknown at compile? For example when reading text input into an array and the size of text can be any length.
Find the size of the file ``` fseek(fp, 0, SEEK_END); size = ftell(fp); /* Rewind. */ fseek(fp, 0, SEEK_SET); ``` Allocate the memory ``` char *buf = malloc(size); ```
I study C. Digging in some C source code where I found that line. I have read about pointers, but I did not see such an example. ``` char *uppercase (char *s); ``` What that mean ?
It's a declaration of a function that takes a char pointer and returns a char pointer.
When writing characters to an array from a stream, is there a way to make the length of the array the exact number of characters if the size of the stream is unknown at compile? For example when reading text input into an array and the size of text can be any length.
Find the size of the file ``` fseek(fp, 0, SEEK_END); size = ftell(fp); /* Rewind. */ fseek(fp, 0, SEEK_SET); ``` Allocate the memory ``` char *buf = malloc(size); ```
I get "implicit declaration of function 'strncmp' isinvalid in C99" when use strncmp (xcode 4/ gcc version 4.2.1) How to avoid this ?
From thestrncmp(3)man page: #include <string.h>
What is the difference between using(char)0and'\0'to denote the terminating null character in a character array?
They're both a 0, but(char) 0is a char, while'\0'is (unintuitively) anint. This type difference should not usually affect your program if the value is 0. I prefer'\0', since that is the constant intended for that.
I do most of my programming on embedded processors, or on linux. When i need to sync data to my persistant store, i usually use the sync(2) system call. Is there an equivelent for Windows?
http://msdn.microsoft.com/en-us/library/aa364439(VS.85).aspxhttp://www.codeproject.com/KB/system/EjectMediaByLetter.aspx FlushFileBuffers with a handle to a volume. You have to do this for every volume :(
I have a macro defined. But I need to change this value at run time depending on a condition. How can I implement this?
Macros are replaced by the preprocessor by their value before your source file even compiles. There is no way you'd be able to change the value of the macro at runtime. If you could explain a little more about the goal you are trying to accomplish undoubtedly there is another way of solving your problem that doesn't include macros.
I'm currently reading about enums in C. I understand how they work, but can't figure out situations where they could be useful. Can you give me some simple examples where the usage of enums is appropriate?
They're often used to group related values together: ``` enum errorcode { EC_OK = 0, EC_NOMEMORY, EC_DISKSPACE, EC_CONNECTIONBROKE, EC_KEYBOARD, EC_PBCK }; ```
I need help developing a circle detection algorithm to detect snooker balls. Does anyone know any algorithms that can be implemented in C and open cv? I'm having trouble getting this done
OpenCV 2.3 comes withHoughCircles. The C++ API for OpenCV 2.1 also implements the function:http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html#HoughCircles
How do you check whether a path is absolute or relative, using C on Linux?
Absolute paths tend to start with the/character. Anything else is pretty much relative from the working directory. Even directories with..sequences in them are considered absolute if they start with/since they end up at the same position in the file system (unless you change links and things but that's beyond the discussion of absolute and relative).
I want to assign 0 to all declared values in a single statement. ``` char r, g, b = 0; ``` The above only assigns 0 to b but not to the other variables
You can do it two ways: ``` char r = 0, g = 0, b = 0; ``` or ``` char r, g, b; r = g = b = 0; ```
I have 3 different processes that all print out single characters usingprintf. But I can't see them in the terminal. When I add a newline,printf("\n H")so each character is on a new line, I can see them. Why doesn't it work without the newline character?
Its a matter of flushing. If you flush the buffers after eachprintf, you should get output closer to what you want. To flush the standard output simply dofflush( stdout ).
Does anyone has an idea for efficient error correction algorithm? Suppose all the operations and manipulation on the stream is on the Byte level.
MaybeReed-Solomon error correction?
I'd like to implent a function forSuperFastHashthat is compatible so openssl's MD5 function. MD5 is declared in md5.h as: ``` unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); ``` But I can't find it's definition in the headers and the sourcecode. So how does it work exactly? The function not the algorithm.
https://www.rfc-editor.org/rfc/rfc1321
I want tosend(socketfd, ...)and I'm using theselect()function. Should this file descriptor be in thewritefds, or in thereadfds?
readfdsare for sockets you want to read from,writefdsfor those you want to write to. Sowritefdsin your case.
I have a following array and a printf() stament, ``` char array[1024] = "My Message: 0x7ffff6be9600"; printf("%.14s", strstr(array, " 0x") + 1); ``` The output of above printf() is 0x7ffff6be9600, can we store it into a unsigned long variable?
Look atsscanf
see i have written one program for big endian now i dont have big endian machine but i want to check whether my program will works correctly or not on big endian so how can i check that on my little endian pc.? Is there any online virtual big-endian compiler ? note : i have googled about this but did not get anything.
qemucan virtualize all sorts of architectures, amongst then big endian ones.
Is there a LPTSTR equivalent of _strnicmp which takes in 2 LPTSTR strings, and number of TCHARs to compare until? using the c winapi btw
It is_tcsncicmp, seethe documentation.
suppose I have a string "2011-08-21 21:48:45 +1200",and another one with the same format,I want to compare these 2 strings to find out which one is the early one or later one,is there a easy way to convert a string to time format rather than compare them by characters? Thanks
usegetdateorstrptime().
I want tosend(socketfd, ...)and I'm using theselect()function. Should this file descriptor be in thewritefds, or in thereadfds?
readfdsare for sockets you want to read from,writefdsfor those you want to write to. Sowritefdsin your case.
I have a following array and a printf() stament, ``` char array[1024] = "My Message: 0x7ffff6be9600"; printf("%.14s", strstr(array, " 0x") + 1); ``` The output of above printf() is 0x7ffff6be9600, can we store it into a unsigned long variable?
Look atsscanf
see i have written one program for big endian now i dont have big endian machine but i want to check whether my program will works correctly or not on big endian so how can i check that on my little endian pc.? Is there any online virtual big-endian compiler ? note : i have googled about this but did not get anything.
qemucan virtualize all sorts of architectures, amongst then big endian ones.
Is there a LPTSTR equivalent of _strnicmp which takes in 2 LPTSTR strings, and number of TCHARs to compare until? using the c winapi btw
It is_tcsncicmp, seethe documentation.
suppose I have a string "2011-08-21 21:48:45 +1200",and another one with the same format,I want to compare these 2 strings to find out which one is the early one or later one,is there a easy way to convert a string to time format rather than compare them by characters? Thanks
usegetdateorstrptime().
Suppose i have a stringconst char *temp = "i am new to C". Now i have a float variablea=1.0000; How can i send the value of "a" insideconst char *tempalong with the existing string. Thanks in advance.
``` const char temp[] = "I am new to C"; float a = 1.0; char buffer[256]; sprintf(buffer, "%s %f", temp, a); ```
I am really frustrated about strncpy function. I did something like this: ``` char *md5S; //which has been assign with values, its length is 44 char final[32]; strncpy(final,md5S,32); ``` but somehow the length ofchar final[]became more than 32 after.What should I do here?
You forgot to leave room for the null character ``` char final[33]; strncpy(final,md5S,32); final[32] = '\0'; ```
I'm trying to convert 64bit integer string to integer, but I don't know which one to use.
Usestrtoullif you have it or_strtoui64()with visual studio. ``` unsigned long long strtoull(const char *restrict str, char **restrict endptr, int base); /* I am sure MS had a good reason not to name it "strtoull" or * "_strtoull" at least. */ unsigned __int64 _strtoui64( const char *nptr, char **endptr, int base ); ```
In multicore systems, such as 2, 4, 8 cores, we typically use mutexes and semaphores to access shared memory. However, I can foresee that these methods would induce a high overhead for future systems with many cores. Are there any alternative methods that would be better for future many core systems for accessing shared memories.
Transactional memoryis one such method.
When I use % operator on float values I get error stating that "invalid operands to binary % (have ‘float’ and ‘double’)".I want to enter the integers value only but the numbers are very large(not in the range of int type)so to avoid the inconvenience I use float.Is there any way to use % operator on such large integer values????
You can use thefmodfunction from the standard math library. Its prototype is in the standard header<math.h>.
How to change the entry point of a C program compiled with gcc ?Just like in the following code ``` #include<stdio.h> int entry() //entry is the entry point instead of main { return 0; } ```
It's a linker setting: ``` -Wl,-eentry ``` the-Wl,...thing passes arguments to the linker, and the linker takes a-eargument to set the entry function
In multicore systems, such as 2, 4, 8 cores, we typically use mutexes and semaphores to access shared memory. However, I can foresee that these methods would induce a high overhead for future systems with many cores. Are there any alternative methods that would be better for future many core systems for accessing shared memories.
Transactional memoryis one such method.
When I use % operator on float values I get error stating that "invalid operands to binary % (have ‘float’ and ‘double’)".I want to enter the integers value only but the numbers are very large(not in the range of int type)so to avoid the inconvenience I use float.Is there any way to use % operator on such large integer values????
You can use thefmodfunction from the standard math library. Its prototype is in the standard header<math.h>.
How to change the entry point of a C program compiled with gcc ?Just like in the following code ``` #include<stdio.h> int entry() //entry is the entry point instead of main { return 0; } ```
It's a linker setting: ``` -Wl,-eentry ``` the-Wl,...thing passes arguments to the linker, and the linker takes a-eargument to set the entry function
Is it considered bad coding to put a break in the default part of a switch statement? A book I was reading said that it was optional but the teacher counted off for using it.
Best practice is to always use abreakunless you mean for control to flow into another case, even at the end of the switch.
I read about some algorithms that can be used to find a string pattren in long text as fast as possible. I am looking for usingaho-corasickalgorithm in executable files, What functions orwin apican be useful to make a binary ready to start searching?.
Here's one free C++ implementation for Windows:link(look for "Aho-Corasick source code" towards the bottom of the page).
I am started to learn Lua few days ago and faced next problem. How can I run the whole lua script form C program, for example, I have a lua script and read it like a text file in my C program so how can I run this script from C side?
By usingluaL_dofile. even no need to read the text file in separately. InProgramming in Lua, they do it using luaL_loadfile (to allow for some more flexibility)
Is it considered bad coding to put a break in the default part of a switch statement? A book I was reading said that it was optional but the teacher counted off for using it.
Best practice is to always use abreakunless you mean for control to flow into another case, even at the end of the switch.
I read about some algorithms that can be used to find a string pattren in long text as fast as possible. I am looking for usingaho-corasickalgorithm in executable files, What functions orwin apican be useful to make a binary ready to start searching?.
Here's one free C++ implementation for Windows:link(look for "Aho-Corasick source code" towards the bottom of the page).
I am started to learn Lua few days ago and faced next problem. How can I run the whole lua script form C program, for example, I have a lua script and read it like a text file in my C program so how can I run this script from C side?
By usingluaL_dofile. even no need to read the text file in separately. InProgramming in Lua, they do it using luaL_loadfile (to allow for some more flexibility)
I am started to learn Lua few days ago and faced next problem. How can I run the whole lua script form C program, for example, I have a lua script and read it like a text file in my C program so how can I run this script from C side?
By usingluaL_dofile. even no need to read the text file in separately. InProgramming in Lua, they do it using luaL_loadfile (to allow for some more flexibility)
I'm wondering if there's a way you can scan an array for a match usingstrcmp. I know the parameters passed tostrcmpare C strings. So something like this wouldn't work: ``` strcmp(arrayofstrings[x], c-string) ```
It would work as long as the arguments can be reduced to of typeconst char*. ``` char *a[] = { "Hello", "Hello" }; // Array of pointers to c strings if ( !strcmp(a[0],a[1]) ){ // true in this case } ```
man ptysays... ``` The BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCREMOTE have not been implemented under Linux. ``` why so? How is these operations taken care of inlinux?
BSD-style PTYshave been deprecated since Linux 2.6.4. System V (UNIX 98)-style PTYs should be used instead. That's probably the reason why theseioctloperations remain unimplemented to this day.
I readhereit is C90 with extensions. How can I know for sure?
Try below command and search forstd ``` gcc -v --help | less ``` It will show you all the available options for your gcc.
Given the path, is there a way to find out whether the file exists without opening the file? Thanks
The most efficient way isaccesswith theF_OKflag. statalso works but it's much heavier weight since it has to read the inode contents, not just the directory.
I'm writting application for embedded system. Where i can download gcc version 3.4.3 with glib version 2.3.4 for Cygwin ? I have download cygwin-gcc-3.3.6-glibc-2.3.2-linux.tar.bz2 but this version isn't suitable for me...
Sometimes linux distributions have a 'compat' packages which make older libraries available. Try searching cygwin for the version of libstdc++ you're looking for.
The only thing that I know about the mechanism of how C passes values is that it is done either through a register or the stack. Register or Stack? Exactly how?
Both. And the conventions will vary by platform. On x86, values are usually passed by stack. On x64, passing by register is preferred. In all cases, if you have too many parameters, some will have to be passed by stack. Refer tox86 calling conventions
Is there an interface in Linux to get notification of a network interface carrier change? I know its possible to poll an interface with SIOCETHTOOL, but was wondering if there was any way to get notified or any blocking calls that would return on carrier detection changes?
Do you need carrier transition or interface state change? For the interface state you could listen to the NETLINK_ROUTE netlink socket and wait for RTM_NEWLINK and RTM_DELLINK messages
I have a string which starts with the character\0- it's by design and I know its actual length. How can I print its representation using escapes like"\0foo\0bar\0", if I know its length?
Well, you should be able to print it as an array: print *str@length
I want to know how I can include special characters in C Strings, i.e.: ``` char a[] = "Hello \120"; // This is just an example ``` Thenashould contain"Hello <120th character>". How can I do this in C?
In hex:char a[] = "Hello \x78";
I want to know how I can include special characters in C Strings, i.e.: ``` char a[] = "Hello \120"; // This is just an example ``` Thenashould contain"Hello <120th character>". How can I do this in C?
In hex:char a[] = "Hello \x78";
For some reason I'm getting an error:statement with no effecton this statement. ``` for (j = idx; j < iter; j + increment) { printf("from loop idx = %i", (int)idx); punc(ctxt, j); } ```
You probably meant to writej += incrementinstead ofj + increment.
I'm trying to make coroutine and continuation with C. I realized I need some kind of spaghetti stack. Is it possible to execute a function within a new call-stack? Of course within single thread. How can I make a new, separated call-stack, and execute some code on it?
check out makecontext/swapcontext. If those aren't available, then you could use setjmp/longjmp, but those are a little more complex.
What is the default WindowProc of a list-view control before I change it usingSetWindowLong()?
That's determined by the system when it registers the window class. It is presumably implemented in comctl32. There's nothing special about one of the built-in window classes in this regard. Just as is the case for a user defined class, the default window proc is whatever was specified when the class was registered.
The return value of an open() was -1 and on trying to find the error using perror() the output was "File exists". How do I find the error or the reason for the file not opening.
Looks like EEXISTpathname already exists and O_CREAT and O_EXCL were used.
I want to be able to tell when my program's stdout is redirected to a file/device, and when it is left to print normally on the screen. How can this be done in C? Update 1: From the comments, it seems to be system dependent. If so, then how can this be done with posix-compliant systems?
Perhapsisatty(stdout)? Edit: As Roland and tripleee suggest, a better answer would beisatty(STDOUT_FILENO).
I was asked this as interview question. Couldn't answer. Write a C program to find size of structure without using thesizeofoperator.
``` struct XYZ{ int x; float y; char z; }; int main(){ struct XYZ arr[2]; int sz = (char*)&arr[1] - (char*)&arr[0]; printf("%d",sz); return 0; } ```
I've looked through the docs and it seems that you can only execute an xpath search from axmlDocPtrby creating anxpath context. Is there anyway inlibxml2to xpath search from axmlNodePtr?
CallxmlXPathNewContext(), specifying the real top-levelxmlDocPtrfor the document, then set thexmlXPathContext::nodefield to the desiredxmlNodePtrpointer that is a child of thexmlDocPtrdocument.
I'm trying to make coroutine and continuation with C. I realized I need some kind of spaghetti stack. Is it possible to execute a function within a new call-stack? Of course within single thread. How can I make a new, separated call-stack, and execute some code on it?
check out makecontext/swapcontext. If those aren't available, then you could use setjmp/longjmp, but those are a little more complex.
What is the default WindowProc of a list-view control before I change it usingSetWindowLong()?
That's determined by the system when it registers the window class. It is presumably implemented in comctl32. There's nothing special about one of the built-in window classes in this regard. Just as is the case for a user defined class, the default window proc is whatever was specified when the class was registered.
The return value of an open() was -1 and on trying to find the error using perror() the output was "File exists". How do I find the error or the reason for the file not opening.
Looks like EEXISTpathname already exists and O_CREAT and O_EXCL were used.
I want to be able to tell when my program's stdout is redirected to a file/device, and when it is left to print normally on the screen. How can this be done in C? Update 1: From the comments, it seems to be system dependent. If so, then how can this be done with posix-compliant systems?
Perhapsisatty(stdout)? Edit: As Roland and tripleee suggest, a better answer would beisatty(STDOUT_FILENO).
I was asked this as interview question. Couldn't answer. Write a C program to find size of structure without using thesizeofoperator.
``` struct XYZ{ int x; float y; char z; }; int main(){ struct XYZ arr[2]; int sz = (char*)&arr[1] - (char*)&arr[0]; printf("%d",sz); return 0; } ```
I've looked through the docs and it seems that you can only execute an xpath search from axmlDocPtrby creating anxpath context. Is there anyway inlibxml2to xpath search from axmlNodePtr?
CallxmlXPathNewContext(), specifying the real top-levelxmlDocPtrfor the document, then set thexmlXPathContext::nodefield to the desiredxmlNodePtrpointer that is a child of thexmlDocPtrdocument.
What's the logic behind calls likegetpid()returning a value of typepid_tinstead of anunsigned int? Orint? How does this help? I'm guessing this has to do with portability? Guaranteeing thatpid_tis the same size across different platforms that may have different sizes ofints etc.?
I think it's the opposite: making the program portable across platforms, regardless of whether, e.g., a PID is 16 or 32 bits (or even longer).
Is ``` void * mremap(void *old_address, size_t old_size , size_t new_size, unsigned long flags); ``` compatible with malloc()? GCC (C++) and using Linux. Thanks.
No, it is not. Apart from the fact thatmallocdoesn't need to give you an address at a page border (which is whatmremapexpects), it would be dangerous to mess with memory mappings frommallocwithoutmallocknowing you did it. Usereallocinstead.
Sorry if this question is silly, but I can't seem to find the answer on Google. I haven't done C programing in a while and for the life of me remember how, in C or C++, to jump back (or forward) to a specific line in code. If I remember right, there was a way to do this. Thanks for the help! Cheers!
The infamous goto, in conjuntion with labels. ``` label_name: goto label_name; ``` Before using it, search for 'goto considered harmful'.
If my application runs 'x' number of threads, and if there are any one of them does the nasty memory corruption, and hence SIGFAULT occurs!!!. Does it affect other threads also ?
Unless you handle it, then yes, it kills the entire application.
I want to obfuscate my dll export names. I have come across the same question in stack overflow in the below link, However I could not find the acceptance of solution.Modify dll exports (symbol table). I want to obfuscate the function names Can anyone suggest?
You can use a .def file, in which you can either give exported functions other names, or just export them by ordinal. SeeExporting from a DLL Using DEF Filesand.def files C/C++ DLLs.