<< < 7 8 9 10 11 12 13 14 15 16 17 > >>   Sort: Date

What are near and far pointers?
What are near and far pointers? These days, they're pretty much obsolete; they're definitely system-specific. They had to do with 16-bit programming under MS-DOS and perhaps some early versions of Windows. If you really need to know, see a DOS- or Windows-specific programming reference. If you're us...
2015-03-02, 1132👍, 0💬

How can I write a macro which takes a variable number of arguments ....
How can I write a macro which takes a variable number of arguments, or use the preprocessor to ``turn off'' a function call with a variable number of arguments? One popular trick is to define and invoke the macro with a single, parenthesized ``argument'' which in the macro expansion becomes the enti...
2016-01-19, 1131👍, 0💬

Is it acceptable for one header file to #include another?
Is it acceptable for one header file to #include another? It's a question of style, and thus receives considerable debate. Many people believe that ``nested #include files'' are to be avoided: the prestigious Indian Hill Style Guide disparages them; they can make it harder to find relevant definitio...
2016-02-16, 1130👍, 0💬

I inherited some code which contains far too many ...
I inherited some code which contains far too many #ifdef's for my taste. How can I preprocess the code to leave only one conditional compilation set, without running it through the preprocessor and expanding all of the #include's and #define's as well? There are programs floating around called unifd...
2016-01-29, 1129👍, 0💬

What does the message Automatic aggregate intialization is an ANSI feature mean?
What does the message Automatic aggregate intialization is an ANSI feature'' mean? My compiler is complaining about valid ANSI code. Messages like these are typically emitted by pre-ANSI compilers which have been upgraded just enough to detect (but not properly translate) new C features which were i...
2015-11-30, 1129👍, 0💬

I have a pre-ANSI compiler, without stdarg.h What can I do?
I have a pre-ANSI compiler, without stdarg.h What can I do? There's an older header, &lt;varargs.h>, which offers about the same functionality. Here is the vstrcat function, rewritten to use &lt;varargs.h>: #include &lt;stdio.h> #include &lt;varargs.h> #include &lt;string.h> exte...
2015-06-10, 1128👍, 0💬

People keep saying that the behavior of ...
People keep saying that the behavior of i = i++ is undefined, but I just tried it on an ANSI-conforming compiler, and got the results I expected. A compiler may do anything it likes when faced with undefined behavior (and, within limits, with implementation-defined and unspecified behavior), includi...
2015-11-18, 1125👍, 0💬

How can I write a function that takes a format string and a variable number of arguments
How can I write a function that takes a format string and a variable number of arguments, like printf, and passes them to printf to do most of the work? Use vprintf, vfprintf, or vsprintf. These routines are like their counterparts printf, fprintf, and sprintf, except that instead of a variable-leng...
2015-06-12, 1125👍, 0💬

How can I send mail from within a C program?
How can I send mail from within a C program? Under Unix, open a pipe to the mail program, or perhaps /usr/lib/sendmail.
2015-04-17, 1125👍, 0💬

How can I implement a delay, or time a users response, with sub-second resolution?
How can I implement a delay, or time a users response, with sub-second resolution? Unfortunately, there is no portable way. Routines you might look for on your system include clock, delay, ftime, gettimeofday, msleep, nap, napms, nanosleep, setitimer, sleep, Sleep, times, and usleep. (A function cal...
2015-03-06, 1125👍, 0💬

If you cant modify string literals, why arent they defined as being arrays of const characters?
If you cant modify string literals, why arent they defined as being arrays of const characters? One reason is that so very much code contains lines like char *p = "Hello, world!"; which are not necessarily incorrect. These lines would suffer the diagnostic messages, but it's really any later attempt...
2016-01-06, 1124👍, 0💬

I had a frustrating problem which turned out to be caused by the line ....
I had a frustrating problem which turned out to be caused by the line printf("%d", n); where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this. A:When a function accepts a variable number of arguments, its prototype d...
2016-01-11, 1123👍, 0💬

How can I make it pause before closing the program output window?
I'm compiling some test programs on a windows-based system, and the windows containing my program's output are closing so quickly after my program calls exit that I can't see the output. How can I make it pause before closing? After wondering why the author of your compiler's run-time system didn't ...
2015-04-24, 1123👍, 0💬

I keep getting errors due to library functions being undefined, but I am including all the right header files.
I keep getting errors due to library functions being undefined, but I am including all the right header files. In the general case of calling code in an external library, using #include to pull in the right header file(s) is only half of the story; you also have to tell the linker to search the exte...
2015-07-14, 1121👍, 0💬

Why does this code crash?
Why does this code: char *p = "hello, world!"; p[0] = 'H'; crash? String constants are in fact constant. The compiler may place them in nonwritable storage, and it is therefore not safe to modify them. When you need writable strings, you must allocate writable memory for them, either by declaring an...
2015-05-27, 1120👍, 0💬

How can I check whether a file exists? I want to warn the user if a requested input file is missing.
How can I check whether a file exists? I want to warn the user if a requested input file is missing. It's surprisingly difficult to make this determination reliably and portably. Any test you make can be invalidated if the file is created or deleted (i.e. by some other process) between the time you ...
2015-04-15, 1120👍, 0💬

My compiler is complaining that printf is undefined ...
My compiler is complaining that printf is undefined! How can this be? It's the world's most popular C function... Allegedly, there are C compilers for Microsoft Windows which do n ot support printf, on the argument that printf is for printing to old-fashioned terminals, while under Windows the right...
2015-07-03, 1119👍, 0💬

I had a frustrating problem which turned out to be caused by the line
I had a frustrating problem which turned out to be caused by the line printf("%d", n); where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this. When a function accepts a variable number of arguments, its prototype doe...
2015-06-15, 1119👍, 0💬

How can I find the modification date and time of a file?
How can I find the modification date and time of a file? The Unix and POSIX function is stat, which several other systems supply as well.
2015-04-13, 1119👍, 0💬

I have some old code that tries to construct identifiers with a macro like ...
I have some old code that tries to construct identifiers with a macro like #define Paste(a, b) a/**/b but it doesn't work any more. It was an undocumented feature of some early preprocessor implementations (notably Reiser's) that comments disappeared entirely and could therefore be used for token pa...
2016-01-27, 1118👍, 0💬

My ANSI compiler complains about a mismatch when it see
My ANSI compiler complains about a mismatch when it sees extern int func(float); int func(x) float x; { ... You have mixed the new-style prototype declaration ``extern int func(float);'' with the old-style definition ``int func(x) float x;''. It is usually possible to mix the two styles but not in t...
2016-01-13, 1117👍, 0💬

I have a program that seems to run correctly
I have a program that seems to run correctly, but it crashes as it's exiting, after the last statement in main(). What could be causing this? A:There are at least three things to look for: 1. If a semicolon in a previous declaration is missing, main might be inadvertently declared as returning a str...
2015-05-29, 1116👍, 0💬

I have got this tricky preprocessing I want to do and I cant figure out a way to do it.
I have got this tricky preprocessing I want to do and I cant figure out a way to do it. C's preprocessor is not intended as a general-purpose tool. (Note also that it is not guaranteed to be available as a separate program.) Rather than forcing it to do something inappropriate, you might want to wri...
2016-01-19, 1115👍, 0💬

How can I access an I O board directly?
How can I access an I O board directly? At one level, at least, it's quite simple: you have a device register which is actually wired up so that the bits written to it get coverted to actual voltage levels in the real world that you can do interesting things with. In general, there are two ways to g...
2015-04-20, 1115👍, 0💬

<< < 7 8 9 10 11 12 13 14 15 16 17 > >>   Sort: Date