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

I am getting baffling syntax errors which make no sense at all
I'm getting baffling syntax errors which make no sense at all, and it seems like large chunks of my program aren't being compiled. Check for unclosed comments, mismatched #if/#ifdef/#ifndef/#else/#endi fdirectives, and perhaps unclosed quotes; remember to check header files, too.
2015-06-01, 1109👍, 0💬

Since array references decay into pointers ...
Since array references decay into pointers, if arr is an array, what's the difference between arr and &arr? The type. In Standard C, &arr yields a pointer, of type pointer-to-array-of-T, to the entire array. (In pre-ANSI C, the & in &arr generally elicited a warning, and was generall...
2015-12-09, 1108👍, 0💬

Dont ANSI function prototypes render lint obsolete?
Dont ANSI function prototypes render lint obsolete? Not really. First of all, prototypes work only if they are present and correct; an inadvertently incorrect prototype is worse than useless. Secondly, lint checks consistency across multiple source files, and checks data declarations as well as func...
2015-05-01, 1108👍, 0💬

People always say that good style is important
People always say that good style is important, but when they go out of their way to use clear techniques and make their programs readable, they seem to end up with less efficient programs. Since efficiency is so important, isn't it necessary to sacrifice some style and readability? It's true that g...
2015-05-06, 1106👍, 0💬

I think somethings wrong with my compiler ...
I think something's wrong with my compiler: I just noticed that sizeof('a') is 2, not 1 (i.e. not sizeof(char)). Perhaps surprisingly, character constants in C are of type int, so sizeof('a') is sizeof(int) (though this is another area where C++ differs).
2016-03-04, 1105👍, 0💬

Can you mix old-style and new-style function syntax?
Can you mix old-style and new-style function syntax? Doing so is legal (and can be useful for backwards compatibility), but requires a certain amount of care . Modern practice, however, is to use the prototyped form in both declarations and definitions. (The old-style syntax is marked as obsolescent...
2016-01-13, 1104👍, 0💬

I dont understand why I cant use const values in initializers ....
I don't understand why I can't use const values in initializers and array dimensions, as in const int n = 5; int a[n]; The const qualifier really means ``read-only''; an object so qualified is a run-time object which cannot (normally) be assigned to. The value of a const-qualified object is therefor...
2016-01-08, 1104👍, 0💬

I am checking a string to see if it matches a particular value...
I'm checking a string to see if it matches a particular value. Why isn't this code working? char *string; ... if(string == "value") { /* string matches "value" */ ... } Strings in C are represented as arrays of characters, and C never manipulates (assigns, compares, etc.) arrays as a whole. The == o...
2016-03-11, 1102👍, 0💬

How can I shut off the warning ...
How can I shut off the ``warning: possible pointer alignment problem'' message which lint gives me for each call to malloc? A modern lint shouldn't be complaining about this. Once upon a time, lint did not and could not know that malloc ``returns a pointer to space suitably aligned for storage of an...
2015-05-05, 1102👍, 0💬

Why cant I perform arithmetic on a void pointer?
Why cant I perform arithmetic on a void pointer? The compiler doesn't know the size of the pointed-to objects. (Remember that pointer arithmetic is always in terms of the pointed-to size; Therefore, arithmetic on void *'s is disallowed (though some compilers allow it as an extension). Before perform...
2015-12-07, 1101👍, 0💬

Why isnt it being handled properly?
I'm reading strings typed by the user into an array, and then printing them out later. When the user types a sequence like \n, why isn't it being handled properly? Character sequences like \n are interpreted at compile time. When a backslash and an adjacent n appear in a character constant or string...
2015-08-24, 1101👍, 0💬

Is if(p), where p is a pointer, a valid and portable test?
Is if(p), where p is a pointer, a valid and portable test? It is always valid. When C requires the Boolean value of an expression, a false value is inferred when the expression compares equal to zero, and a true value otherwise. That is, whenever one writes if(expr) where ``expr'' is any expression ...
2016-02-29, 1098👍, 0💬

Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0?
Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0? It's your choice. Preprocessor macros like TRUE and FALSE (and, of course, NULL) are used for code readability, not because the underlying values might ever change. It's a matter of style, not correctness, wheth...
2015-05-11, 1098👍, 0💬

Why does the call char scanf work?
Why does the call char s[30]; scanf("%s", s); work? I thought you always needed an & on each variable passed to scanf. You always need a pointer; you don't necessarily need an explicit &amp;. When you pass an array to scanf, you do not need the &, because arrays are always passed to func...
2015-10-30, 1097👍, 0💬

How can I sort a linked list?
How can I sort a linked list? Sometimes it's easier to keep the list in order as you build it (or perhaps to use a tree instead). Algorithms like insertion sort and merge sort lend themselves ideally to use with linked lists. If you want to use a standard library function, you can allocate a tempora...
2015-08-10, 1097👍, 0💬

I am porting this program, and it calls a routine drand48, which my library doesnt have. What is it?
I am porting this program, and it calls a routine drand48, which my library doesnt have. What is it? drand48 is a Unix System V routine which returns floating point random numbers (presumably with 48 bits of precision) in the half-open interval [0, 1). (Its companion seed routine is srand48; neither...
2015-07-20, 1094👍, 0💬

I am trying to define a few simple little function-like macros ...
I'm trying to define a few simple little function-like macros such as #define square(x) x * x but they're not always working. There are three important rules to remember when defining function-like macros: 1. The macro expansion must always be parenthesized to protect any lower-precedence operators ...
2016-02-26, 1093👍, 0💬

If I can say... why can't I say...
If I can say char a[] = "Hello, world!"; why can't I say char a[14]; Strings are arrays, and you can't assign arrays directly. Use strcpy instead: strcpy(a, "Hello, world!");
2016-03-11, 1092👍, 0💬

How can I insert or delete a line (or record) in the middle of a file?
How can I insert or delete a line (or record) in the middle of a file? In general, there is no way to do this. The usual solution is simply to rewrite the file. When you find yourself needing to insert data into an existing file, here are a few alternatives you can try: * Rearrange the data file so ...
2015-10-05, 1092👍, 0💬

Once I have used freopen, how can I get the original stdout (or stdin) back?
Once I have used freopen, how can I get the original stdout (or stdin) back? There isn't a good way. If you need to switch back, the best solution is not to have used freopen in the first place. Try using your own explicit output (or input) stream variable, which you can reassign at will, while leav...
2015-10-01, 1092👍, 0💬

Is exit(status) truly equivalent to returning the same status from main?
Is exit(status) truly equivalent to returning the same status from main? Yes and no. The Standard says that a return from the initial call to main is equivalent to calling exit. However, a return from main cannot be expected to work if data local to main might be needed during cleanup; A few very ol...
2015-07-20, 1091👍, 0💬

Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme
Some people say that gotos are evil and that I should never use them. Isnt that a bit extreme rogramming style, like writing style, is somewhat of an art and cannot be codified by inflexible rules, although discussions about style often seem to center exclusively around such rules. In the case of th...
2015-05-08, 1090👍, 0💬

My compiler isnt letting me declare a function
My compiler isnt letting me declare a function A; My compiler isn't letting me declare a function int f(...) { } i.e. accepting a variable number of arguments, but with no fixed arguments at all. A: Standard C requires at least one fixed argument, in part so that you can hand it to va_start. (In any...
2015-06-08, 1088👍, 0💬

How can I read a binary data file properly?
How can I read a binary data file properly? I'm occasionally seeing 0x0a and 0x0d values getting garbled, and I seem to hit EOF prematurely if the data contains the value 0x1a. When you're reading a binary data file, you should specify "rb" mode when calling fopen, to make sure that text file transl...
2015-09-24, 1087👍, 0💬

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