question
stringlengths
24
425
answer
stringlengths
5
405
I'm using multithreading in my application with _beginthread and right now to wait until all threads are done I have global bools that get set to true as each thread completes so I'm in a while loop until then. There must be a cleaner way of doing this? Thanks
You can useWaitForMultipleObjectsto wait for the threads to finish in primary thread.
I have aFILE *, returned by a call tofopen(). I need to get a file descriptor from it, to make calls likefsync(fd)on it. What's the function to get a file descriptor from a file pointer?
The proper function isint fileno(FILE *stream). It can be found in<stdio.h>, and is a POSIX standard but not standard C.
Which version of ANSI C standard does Turbo C 3.0 follow wholly or partly? C89 or C90 ?
Turbo C++ 3.0 was released in 1991, which means that in its C compilation it probably supports K&R C and C89 (C90 was essentially identical). It won't support C95 well, because that version of the standard wasn't available.
What code do we use to move at a point on the screen in graphics mode(graphics.h)?As in normal we use goto(x,y).
Since you don't have a choice in the matter, here are some tutorials on drawing stuff withgraphics.h: Part 1Part 2Part 3
I have aFILE *, returned by a call tofopen(). I need to get a file descriptor from it, to make calls likefsync(fd)on it. What's the function to get a file descriptor from a file pointer?
The proper function isint fileno(FILE *stream). It can be found in<stdio.h>, and is a POSIX standard but not standard C.
Which version of ANSI C standard does Turbo C 3.0 follow wholly or partly? C89 or C90 ?
Turbo C++ 3.0 was released in 1991, which means that in its C compilation it probably supports K&R C and C89 (C90 was essentially identical). It won't support C95 well, because that version of the standard wasn't available.
What code do we use to move at a point on the screen in graphics mode(graphics.h)?As in normal we use goto(x,y).
Since you don't have a choice in the matter, here are some tutorials on drawing stuff withgraphics.h: Part 1Part 2Part 3
What code do we use to move at a point on the screen in graphics mode(graphics.h)?As in normal we use goto(x,y).
Since you don't have a choice in the matter, here are some tutorials on drawing stuff withgraphics.h: Part 1Part 2Part 3
which of these two is better? ``` void SetBit(int *flag, int bit) { *flag |= 1 << bit; } ``` Or ``` int SetBit(int flag, int bit) { flag |= 1 << bit; return flag; } ```
I like the second one because it doesn't have any side effects. If you want to modifyflag, you can simply assign the result to itself: ``` flag = SetBit(flag, 4); ```
i use gconf/gconf-client.h in ,y C application, but i don't know, is gconf on users machine. How can i check gconf/gconf-client.h and gconf there or not? Thank you
If the code compiles then probably its already installed. Otherwise you can download the package and install it. If you use thepkg-config --cflags gconf-2.0and compile, gcc will give corresponding error if the package doesnt exist in the PKG_CONFIG_PATH.
I get a segfault from this line of code: ``` int fatblob[1820][286][5]; ``` Why is that?
Because your stack segment is smaller then1820*285*5ints. It's usually in a neighborhood of 1MB.
Is it possible to decompile third-party shared libraries built for solaris into C code?
Sort of. The short answer is: not really well. The long answer is to read what REC and other "reverse" compilers do. Maybe try here REC: http://www.backerstreet.com/rec/rec.htm try Rational Rose as well: http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/Tools/Rose.html They can create C. or C++. Whether you can read it is another story.
I get a segfault from this line of code: ``` int fatblob[1820][286][5]; ``` Why is that?
Because your stack segment is smaller then1820*285*5ints. It's usually in a neighborhood of 1MB.
Is it possible to decompile third-party shared libraries built for solaris into C code?
Sort of. The short answer is: not really well. The long answer is to read what REC and other "reverse" compilers do. Maybe try here REC: http://www.backerstreet.com/rec/rec.htm try Rational Rose as well: http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/Tools/Rose.html They can create C. or C++. Whether you can read it is another story.
How can I imposeGdkDrawingAreaon theGtkImagefor painting on an image, for example?
GtkDrawingAreaandGtkImageare different classes, so you must choose one of them. You can still draw onGtkImage(and on any other widget), by connecting toexpose_eventsignal. You could also use plainGtkDrawingArea- displaying image is a matter of callinggdk_draw_pixbuffunction.
I need to get the millisecond accuracy. I take a look onthis questionbut I am working on Windows: it gives linking errors for POSIX functions. It will be very good if I can get UTC time since 1970 with milliseconds precision.
Not in ANSI C, but the Windows API provides aGetSystemTimefunction as illustrated here:https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
Using Glib Testing framework, I would like to know if I can reuse a pointer queued to be freed with g_test_queue_free? Here's a code sample of what I'm trying to do: ``` static void some_test() { gchar* tmp; tmp = func_returning_gchar_ptr (...params...); g_assert(tmp); g_test_queue_free(tmp); tmp = func_returning_gchar_ptr (...params...); g_assert(tmp); g_test_queue_free(tmp); ... } ```
Yes that should be fine
Suppose I do asystem("ps-C nautilus");how do I return the result of this function in char* ? Thank you.
You don't. Not sure what platform you're on, but have a look at thepopenfunction instead. You'll get a bidirectional pipe this way, which you can do file operations on, like reading to get a string out of it.
I want to make a simple just-in-time compiler with c on Linux. How can I allocate memory such that I can write out raw x86 code to it and execute it as any other function?
See mprotect(). Once you have filled a (n-)page-sized memory region (allocated with mmap()) with code, change its permissions to disallow writes and allow execution.
I noticed that Snipping Tool (On Windows Vista / 7) has a Toolbar control. I'v used Spy++ and copied its exact styles but when I press down, it does not do like theirs. Theirs stays stuck on the clicked control, indicating that this tool is 'in use' I want to have this effect in my application. Thanks
I don't have a NT6 system near me ATM but I think you are just talking about the BSTYLE_CHECK toolbar button style
How could I create a control that looks like this one:http://img195.imageshack.us/img195/4268/eeeeae.png http://img195.imageshack.us/img195/4268/eeeeae.png I just want that small end. Thanks
If that's a Windows ComboBox control with a visual style applied to it, you can render its themed button wherever you like usingDrawThemeBackground()andCP_DROPDOWNBUTTON.
Before I start building one myself; Is there a wrapper for C or C++ which does the same thing asSVNKit?
There is an API provided in C - see theSubversion Documentation
I'm using a Win32 Header. I want to make it so that the header item I click on stays 'selected' or looks selected until I press another one. I want to avoid disabling it for aesthetic reasons. Thanks
If this header is part of a listview, you can provide a visual clue withListView_SetSelectedColumn
Why are reference variables not present/used in C? Why are they designed for C++?
Because C was invented first. I don't know if they hadn't thought about references at the time (being mostly unnecessary), or if there was some particular reason not to include them (perhaps compiler complexity). They're certainly much more useful for object-oriented and generic constructs than the procedural style of C.
I want to be able to know how much room a particular tab takes up, is there a way to calculate this knowing it's text and having its item struct? Thanks
Assuming a SysTabControl how aboutTCM_GETITEMRECT?
This question already has answers here:Closed13 years ago. Possible Duplicate:C pointer to array/array of pointers disambiguation In C, isint *thing[5]an array of five pointers, each pointing to an integer, or a pointer to an array of five integers?
[]trumps*per theC precedence tablewhich means you have an array of five int pointers.
This question already has answers here:Closed13 years ago. Possible Duplicates:what does malloc(0) return ?what’s the point in malloc(0)? Why does malloc(0) return valid memory address ? What's the use ?
If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer. Source:mallocat The Open Group
is "register struct" legal? In terms of standards and (separated from standards) in Gcc?
Yes. (No citation, there is simply no prohibition on that. There is a note assuming that the use of register with arrays is valid, and arrays are far more second class citizen in C that structs).
Is there an easy way to read/write a nibble in a byte without using bit fields? I'll always need to read both nibbles, but will need to write each nibble individually. Thanks!
Use masks : ``` char byte; byte = (byte & 0xF0) | (nibble1 & 0xF); // write low quartet byte = (byte & 0x0F) | ((nibble2 & 0xF) << 4); // write high quartet ``` You may want to put this inside macros.
I have UTC time which is coming from UDP, I have a program to calculate Day and Time of UTC, how can I set my system clock at that day and time, kindly give me some direction so that I can make it possible. I am using Window OS.
To set the current system time, use theSetSystemTimeWin32 API function.
What is the difference betweenunsigned longandUINT64? I think they are the same, but I'm not sure. The definition ofUINT64is : ``` typedef unsigned __int64 UINT64 ``` (by using StdAfx.h)
UINT64 is specific and declares your intent. You want a type that is an unsigned integer that is exactly 64 bits wide. That this may be equal to an unsigned long on some platforms is coincidence.
I have installed linux 2.6. I wanted to know if there are any drivers to access the GPR port pins.
Look for a/dev/gpiofile.This linkshows some C code that accesses the GPIO pins. Please note that the exact way this works might differ with different ARM Linux distributions, and you don't give a lot of detail in your question.
Before I start building one myself; Is there a wrapper for C or C++ which does the same thing asSVNKit?
There is an API provided in C - see theSubversion Documentation
I'm using a Win32 Header. I want to make it so that the header item I click on stays 'selected' or looks selected until I press another one. I want to avoid disabling it for aesthetic reasons. Thanks
If this header is part of a listview, you can provide a visual clue withListView_SetSelectedColumn
Why are reference variables not present/used in C? Why are they designed for C++?
Because C was invented first. I don't know if they hadn't thought about references at the time (being mostly unnecessary), or if there was some particular reason not to include them (perhaps compiler complexity). They're certainly much more useful for object-oriented and generic constructs than the procedural style of C.
I want to be able to know how much room a particular tab takes up, is there a way to calculate this knowing it's text and having its item struct? Thanks
Assuming a SysTabControl how aboutTCM_GETITEMRECT?
This question already has answers here:Closed13 years ago. Possible Duplicate:C pointer to array/array of pointers disambiguation In C, isint *thing[5]an array of five pointers, each pointing to an integer, or a pointer to an array of five integers?
[]trumps*per theC precedence tablewhich means you have an array of five int pointers.
This question already has answers here:Closed13 years ago. Possible Duplicates:what does malloc(0) return ?what’s the point in malloc(0)? Why does malloc(0) return valid memory address ? What's the use ?
If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer. Source:mallocat The Open Group
is "register struct" legal? In terms of standards and (separated from standards) in Gcc?
Yes. (No citation, there is simply no prohibition on that. There is a note assuming that the use of register with arrays is valid, and arrays are far more second class citizen in C that structs).
Is there an easy way to read/write a nibble in a byte without using bit fields? I'll always need to read both nibbles, but will need to write each nibble individually. Thanks!
Use masks : ``` char byte; byte = (byte & 0xF0) | (nibble1 & 0xF); // write low quartet byte = (byte & 0x0F) | ((nibble2 & 0xF) << 4); // write high quartet ``` You may want to put this inside macros.
I have UTC time which is coming from UDP, I have a program to calculate Day and Time of UTC, how can I set my system clock at that day and time, kindly give me some direction so that I can make it possible. I am using Window OS.
To set the current system time, use theSetSystemTimeWin32 API function.
What is the difference betweenunsigned longandUINT64? I think they are the same, but I'm not sure. The definition ofUINT64is : ``` typedef unsigned __int64 UINT64 ``` (by using StdAfx.h)
UINT64 is specific and declares your intent. You want a type that is an unsigned integer that is exactly 64 bits wide. That this may be equal to an unsigned long on some platforms is coincidence.
I have installed linux 2.6. I wanted to know if there are any drivers to access the GPR port pins.
Look for a/dev/gpiofile.This linkshows some C code that accesses the GPIO pins. Please note that the exact way this works might differ with different ARM Linux distributions, and you don't give a lot of detail in your question.
In .Net there is something called a menu strip. These are more customizable than HMENU's. How could I create one of these in unmanaged C++? Thanks
They aren't more customizable than HMENUs, they're justeasierto customize. If you don't want to useMFC C++ WinAPI wrapper, what do you want to customize ?
How can I get Visual Studio to help me optimize my application, or tell me areas of slowness? Thanks
If you have Visual Studio 2013 Professional then you can use the Performance and Diagnostics hub:http://blogs.msdn.com/b/visualstudioalm/archive/2013/07/12/performance-and-diagnostics-hub-in-visual-studio-2013.aspx. This profiler is well integrated in the IDE and I've found it really quick and easy for spotting code hotspots.
How can I get Visual Studio to help me optimize my application, or tell me areas of slowness? Thanks
If you have Visual Studio 2013 Professional then you can use the Performance and Diagnostics hub:http://blogs.msdn.com/b/visualstudioalm/archive/2013/07/12/performance-and-diagnostics-hub-in-visual-studio-2013.aspx. This profiler is well integrated in the IDE and I've found it really quick and easy for spotting code hotspots.
I need to find the duration of numerous formats of audio and video files, in milliseconds. I've been searching around for a while, but I can't find anything that will let me do this. I'm using C/++ in Linux. Thanks in advance.
There is aMediaInfoSourceFourge project that shows this info. You can look in its code for that.
Is there a way to make a toolbar button look different than the rest (Aside from changing bitmap or setting its state to Disable? Is there away to make it look highlighted all the time? I want the selected tool to look selected. Thanks (Sort of like the way open applications are "Selected" in Windows 7.
Send the TB_SETHOTITEM message
Can I use a forloop to get the property names of a "struct" in C? Or would I just have make a separate list? (Just the name I am looking for)
You'll have to make a separate list. The C programming language doesn't have any introspection capabilities that would let you enumerate the property names of a struct.
When a menu item or context menu is made, it has a shadow, if I create a window with WS_POPUP instead of WS_CHILD it has no shadow. How can I get the shadow? Thanks
It is enabled with WNDCLASSEX.style. Turn on theCS_DROPSHADOW style. I think this only works on top-level windows.
I notice Vista/7 uses this type of control as well as Windows Live Messenger. This is the control: How can this control be programably added to a WinAPI application? Thanks
This resource is Bitmap 7016 in explorer.exe's resources. It is a 32 bit bitmap, so it has an extra alpha channel. This is how it is done.
What will be solution in the following code ``` Class A{} void func(){} printf("%d,%d",sizeof(A),sizeof(func)); ```
Size of an empty class is non zero(most probably 1), so as to have two objects of the class at different addresses. http://www2.research.att.com/~bs/bs_faq2.html#sizeof-emptyexplains it better ``` class A{}; void func(){} std::cout<<sizeof(A)<<std::endl<<sizeof(&func));// prints 1 and 4 on my 32 bit system ```
I'm wondering what the stencil buffer is and what it can do.
http://en.wikipedia.org/wiki/Stencil_buffer Basically, the stencil buffers allows you to draw only in parts "marked" in the stencil buffer, rejecting pixels where this "mark" doesn't have certain value. Is used to clip rendering in non-rectangular shapes, and to doshadow volumes.
What will be solution in the following code ``` Class A{} void func(){} printf("%d,%d",sizeof(A),sizeof(func)); ```
Size of an empty class is non zero(most probably 1), so as to have two objects of the class at different addresses. http://www2.research.att.com/~bs/bs_faq2.html#sizeof-emptyexplains it better ``` class A{}; void func(){} std::cout<<sizeof(A)<<std::endl<<sizeof(&func));// prints 1 and 4 on my 32 bit system ```
I'm wondering what the stencil buffer is and what it can do.
http://en.wikipedia.org/wiki/Stencil_buffer Basically, the stencil buffers allows you to draw only in parts "marked" in the stencil buffer, rejecting pixels where this "mark" doesn't have certain value. Is used to clip rendering in non-rectangular shapes, and to doshadow volumes.
Can anyone explain what I'm doing wrong here to not get 11 as my output? ``` void foo { int *n = malloc(sizeof(int)); *n = 10; n++; printf("%d", *n) } ```
n++increments the pointern, not the integer pointed to byn. To increment the integer, you need to dereference the pointer and then increment the result of that: ``` (*n)++; ```
What are some data structures that help me storing and calculating the factorial for numbers with more than 50 digits?
Try anArbitrary Precisioninteger library likeGMPorBigDigits.
Some laptops have a trackpad that can do horizontal scrolling as well as vertical (WM_MOUSEWHEEL), and some desktop mice have ability to tilt their wheels. How can I handle horizontal scrolling from a trackpad or mouse wheel?
WM_MOUSEHWHEELis sent to the active window when the mouse's horizontal scroll wheel is tilted or rotated, and is also useful for horizontal scrolling from a trackpad's horizontal scrolling control
In the following piece of code, ``` #include<stdio.h> typedef struct { int bit1:1; int bit3:4; int bit4:4; } node; int main(){ node n,n1,n2,ff[10]; printf("%d\n",sizeof(node)); return 0; } ``` How do I predict the size of the structure?
You cannot predict it without knowing the compiler and the target platform it compiles to.
How can I retrieve uptime under linux using C? (without using popen and/or /proc) Thanks
Viatopor viauptime, but I don't know about any syscall, someone will for sure :) uptimeshould be rather easy to parse. Just stumbled into this: ``` #include <sys/sysinfo.h> struct sysinfo info; sysinfo(&info); printf("Uptime = %ld\n", info.uptime); ```
Is there a Cocoa class has similar functionality to enumerated values from C? I know that I can just use enums in Cocoa, but what if I want to put an enum in an NSArray (which only accepts objects)?
An enum is just an integer type - you can wrap it inNSNumberto put it in anNSArray.
Is there any way to write log(base 2) function? The C language has 2 built in function -->> 1.logwhich is base e. 2.log10base 10; But I need log function of base 2.How to calculate this.
Simple math: log2(x) = logy(x) / logy(2) whereycan be anything, which for standard log functions is either 10 ore.
I would like to create a pseudo filesystem like /proc to access an applications configuration. How could i achieve this or where could i find some introductory documentation about it?
The easiest way is to useFUSE. This is particularly easy with high-level language bindings, such asfuse-python.
I read something like pointer must be byte-aligned. My understanding in a typical 32bit architecture... all pointers are byte aligned...No ? Please confirm. can there be a pointer which is not byte-aligned ? Basically this is mentioned in a hardware reference manual for tx descriptor memory.
Yes, you cannot address any amount of memory smaller than a byte.
I want to print"%SomeString%"in C. Is this correct? ``` printf("%%s%",SomeString); ```
No, %% outputs %, so the right syntax is: ``` printf("%%%s%%",string); ```
What is the correct syntax for this code: is it: ``` printf("printf(\"\%d\",%s);", some_var); ``` or ``` printf("printf(\"%%d\",%s);", some_var); ``` Or something else?
The second one.%dis defined by printf, not the C language, so you need to escape it with the printf%%, not a character escape. A more complex example with a character escape sequence: ``` printf("printf(\"%%d\\n\",%s);\n", some_var); ```
This question already has answers here:Closed13 years ago. Possible Duplicate:Cross Platform C library for GUI Apps? Is there any crossplatform GUI library for C language? (I mean at least win mac lin) If there is any XML-like GUI editing model, any GUI editing crossplatform visual programms it'l be grate!)
Take a look at theIUP Toolkit. It is written largely in C, and is also easily bound toLua.
In C in Windows, how do I open a website using the default browser? In Mac OS X, I dosystem("open http://url");
You have to useShellExecute(). The C code to do that is as simple as: ``` ShellExecute(NULL, "open", "http://url", NULL, NULL, SW_SHOWNORMAL); ``` This was documented by Microsoft Knowledge Base article KB 224816, but unfortunately the article has been retired and there's no archived version of it.
What type T makes the following code compilable? ``` T f(){ return &f; } ``` I'd prefer a C answer, but I marked the question as C and C++ in case there is only an answer using templates.
I hope this isn't cheating (C++ only): ``` class T { private: T (*_func)(); public: T(T (*func)()) : _func(func) {} T operator()() { return *this; } }; T f() { return &f; } int main() { f()()()()()()()(); } ```
Is there any crossplatform C library for using Pixel Shading filters? to run pixel shader inside your programm, beter as native part of your programm (not like precompiled file), and better for using with abstract data - not only images
Does this do what you want?http://www.khronos.org/opencl/The question is not very detailed, or clear, but I think OpenCL qualifies as an answer...
Is there any crossplatform small\portable C image editing library?
TheIMlibrary is cross platform and supports a very wide array of operations on images out of the box. It can also be extended. Its close relativeCDis also occasionally useful for creating text and line art to annotate an image. Both are readily scripted fromLua.
I would like to create a pseudo filesystem like /proc to access an applications configuration. How could i achieve this or where could i find some introductory documentation about it?
The easiest way is to useFUSE. This is particularly easy with high-level language bindings, such asfuse-python.
I read something like pointer must be byte-aligned. My understanding in a typical 32bit architecture... all pointers are byte aligned...No ? Please confirm. can there be a pointer which is not byte-aligned ? Basically this is mentioned in a hardware reference manual for tx descriptor memory.
Yes, you cannot address any amount of memory smaller than a byte.
I want to print"%SomeString%"in C. Is this correct? ``` printf("%%s%",SomeString); ```
No, %% outputs %, so the right syntax is: ``` printf("%%%s%%",string); ```
I have enabled blur on my window. I have some edit fields and some custom controls and I would not want these to be affected by the blur, they are semi transparent as a result. How could I only blur the main window itself, not its child controls (sort of like Chrome). Thanks
Black is treated as transparent since good old GDI does not support alpha channel (the alpha byte in ARGB is always 0) I'm thinking you have to do some sort ofowner draw.
How can i get the paths of a folder and its content. Say i have folder named MyFolder as /tmp/MyFolder/ where it has subfolders SubFolder1, SubFolder2... and some files
You may take a look at theopendir()family functions.
How can i copy multiple char* variables into one char* at single instance operation. say i have char* text1 = "Hello"; char* text2 = "World"; i want to copy text1, text2 and '2' and "12345" into char* text3 in single function call.
``` char text3[100]; sprintf( text3, "%s%s%s%s", text1, text2, "2", "12345" ); ```
How can i create a temporary folder in /tmp directory.
Try themkdtempfunction. ``` char *tmpdir; strcpy (template, "/tmp/myprog.XXXXXX"); tmpdir = mkdtemp (template); if (!tmpdir) { // Error out here } printf ("Temporary directory created : %s", tmpdir); ```
I have enabled blur on my window. I have some edit fields and some custom controls and I would not want these to be affected by the blur, they are semi transparent as a result. How could I only blur the main window itself, not its child controls (sort of like Chrome). Thanks
Black is treated as transparent since good old GDI does not support alpha channel (the alpha byte in ARGB is always 0) I'm thinking you have to do some sort ofowner draw.
How can i get the paths of a folder and its content. Say i have folder named MyFolder as /tmp/MyFolder/ where it has subfolders SubFolder1, SubFolder2... and some files
You may take a look at theopendir()family functions.
How can i copy multiple char* variables into one char* at single instance operation. say i have char* text1 = "Hello"; char* text2 = "World"; i want to copy text1, text2 and '2' and "12345" into char* text3 in single function call.
``` char text3[100]; sprintf( text3, "%s%s%s%s", text1, text2, "2", "12345" ); ```
How can i create a temporary folder in /tmp directory.
Try themkdtempfunction. ``` char *tmpdir; strcpy (template, "/tmp/myprog.XXXXXX"); tmpdir = mkdtemp (template); if (!tmpdir) { // Error out here } printf ("Temporary directory created : %s", tmpdir); ```
Is this from the C standard?
If you're confused by a C declaration, you can use thecdeclprogram to explain it: ``` ~$ cdecl Type `help' or `?' for help cdecl> explain char (*a)[12]; declare a as pointer to array 12 of char ```
I have code which works on windows, that callsLocalAllocas follows: ``` LocalAlloc(LMEM_ZEROINIT, size) ``` I need the equivalent malloc or calloc call to get this to work on Unix systems, through Mono. Simple answer?
From what I understand it just allocs zeroed memory, so acalloc(1, size)should suffice to allocatesizezeroed bytes.
I hear 3 years ago problem and apparently have infinity solutions. I want to find one of this infinity set. Problem:Write program (have only one file example "selfsource.c") who printing on stdout self source code and exits. All techniques all alowed. Anyone can help me?
This is called aQuine. Wikipedia has anexample in C.
Is this from the C standard?
If you're confused by a C declaration, you can use thecdeclprogram to explain it: ``` ~$ cdecl Type `help' or `?' for help cdecl> explain char (*a)[12]; declare a as pointer to array 12 of char ```
I have code which works on windows, that callsLocalAllocas follows: ``` LocalAlloc(LMEM_ZEROINIT, size) ``` I need the equivalent malloc or calloc call to get this to work on Unix systems, through Mono. Simple answer?
From what I understand it just allocs zeroed memory, so acalloc(1, size)should suffice to allocatesizezeroed bytes.
I hear 3 years ago problem and apparently have infinity solutions. I want to find one of this infinity set. Problem:Write program (have only one file example "selfsource.c") who printing on stdout self source code and exits. All techniques all alowed. Anyone can help me?
This is called aQuine. Wikipedia has anexample in C.
anyone has an idea how to?
I suggest FindFirstFile() and FindNextFile(). Docs with nice example -http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
How to search fast in a non-sorted array? I am unable to think of any other search mechanism apart from linear search. Any pointers will be helpful.
Yes, without sorting the data a linear search is about as good as you can do.
I am using Ubuntu and I want to read the version of its kernel. I found a file named version in /proc/ that records the version of the current kernel. If I dont want to read file, is there any other way, like built-in function in C, that I can read the version in C? Thanks
You can use theuname()system call.
Does C support inheritance? If so, is it by usingstructs since classes are not defined in C?
Yes, it does. Seehttp://gcc.gnu.org/ml/gcc/2010-05/msg00725.html. See Axel-Tobias Schreiner's bookObject-Oriented Programming with ANSI C. There's an English translation of it available. Also, seeObject-orientation in CandHow can Inheritance be modelled using C?.
I have simple from written on C/gtk+ and i have function in this appliction. I need to run this function in a separate thread from gui form. Where can i see example? Thank you.
http://www.yolinux.com/TUTORIALS/GDK_Threads.html
I need to write such a define in C/C++ ``` #define scanf( fscanf(inf, ``` in order to replace eachscanf(withfscanf(inf,literary But I do not know how... Thanks
You want to use aVariadic macro. In your case, I believe you want: ``` #define scanf(...) fscanf(inf,__VA_ARGS__) ```
I need to write such a define in C/C++ ``` #define scanf( fscanf(inf, ``` in order to replace eachscanf(withfscanf(inf,literary But I do not know how... Thanks
You want to use aVariadic macro. In your case, I believe you want: ``` #define scanf(...) fscanf(inf,__VA_ARGS__) ```
What are these data types for? __m64, __m128, __m256 ?
A quick google-search gives me: The __m64 data type is for use with the MMX and 3DNow! intrinsicsThe __m128 data type, for use with the Streaming SIMD Extensions and Streaming SIMD Extensions 2 instructions intrinsics Unfortunately I can't readily find what __m256 is but I suspect it is along the same lines. Basically, data structures for MMX and similar technologies.
I have this code: ``` #include <stdio.h> #include <wchar.h> int main() { wchar_t *foo = L"ðħ"; wprintf(L"[%ls]\n", foo); return 0; } ``` And when I compile it, it gives me theimplicit declaration of function ‘wprintf’warning. I know that I should link the wchar library during compilation, but how do I do that?
Have you tried invoking the compiler with -std=c99 ?
How can I make GNU Make use a different compiler without manually editing the makefile?
You should be able to do something like this: ``` make CC=my_compiler ``` This is assuming whoever wrote the Makefile used the variable CC.
``` char in[100], *temp[10],var[10][10]; int i, n = 0, double val[10]; var[0][]="ANS"; ``` I want to assign a string to var[0][0,1,2] which is 'ANS', but does not work and i cannot figure where i am wrong about this
Perhaps instead using, ``` strncpy(var[0], "ANS", 3); ```
This question already has answers here:Closed13 years ago. Possible Duplicate:How to generate a random number from within a range - C I'm looking for something I can use in C that will give me a random number between a and b. So something like rand(50) would give me a number between 1 and 50.
From the comp.lang.c FAQ:How can I get random integers in a certain range?