<< < 157 158 159 160 161 162 163 164 165 166 167 > >>   Sort: Date

I have seen function declarations that look like this
I've seen function declarations that look like this: extern int func __((int, int)); What are those extra parentheses and underscores for? They're part of a trick which allows the prototype part of the function declaration to be turned off for a pre-ANSI compiler. Somewhere else is a conditional def...
2015-05-23, 1354👍, 0💬

How do you use DBCC statements to monitor various ASPects of a SQL Server installation?
How do you use DBCC statements to monitor various ASPects of a SQL Server installation? Database Consistency Checker (DBCC) - Is a statement used to check the logical and physical consistency of a database, check memory usage, decrease the size of a database, check performance statistics, and so on....
2014-10-20, 1353👍, 0💬

You cant use dynamically-allocated memory after you free it?
You cant use dynamically-allocated memory after you free it? No. Some early documentation for malloc stated that the contents of freed memory were ``left undisturbed,'' but this ill-advised guarantee was never universal and is not required by the C Standard. Few programmers would use the contents of...
2016-04-04, 1349👍, 0💬

I am allocating structures which contain pointers to other dynamically ....
I'm allocating structures which contain pointers to other dynamically-allocated objects. When I free a structure, do I also have to free each subsidiary pointer? Yes. malloc knows nothing about structure declarations or about the contents of allocated memory; it especially does not know whether allo...
2016-03-31, 1348👍, 0💬

How can I determine whether a machines byte order is big-endian or little-endian?
How can I determine whether a machines byte order is big-endian or little-endian? The usual techniques are to use a pointer: int x = 1; if(*(char *)&amp;x == 1) printf("little-endian\n"); else printf("big-endian\n"); or a union: union { int i; char c[sizeof(int)]; } x; x.i = 1; if(x.c[0] == 1) p...
2015-02-16, 1338👍, 0💬

How do I round numbers?
How do I round numbers? The simplest and most straightforward way is with code like (int)(x + 0.5) C's floating to integer conversion truncates (discards) the fractional part, so adding 0.5 before truncating arranges that fractions &gt;= 0.5 will be rounded up. (This technique won't work properl...
2015-06-26, 1335👍, 0💬

How does free know how many bytes to free?
How does free know how many bytes to free? The malloc/free implementation remembers the size of each block as it is allocated, so it is not necessary to remind it of the size when freeing. (Typically, the size is stored adjacent to the allocated block, which is why things usually break badly if the ...
2016-03-24, 1332👍, 0💬

y program is crashing, apparently somewhere down inside malloc ....
My program is crashing, apparently somewhere down inside malloc, but I can't see anything wrong with it. Is there a bug in malloc? It is unfortunately very easy to corrupt malloc's internal data structures, and the resulting problems can be stubborn. The most common source of problems is writing mor...
2016-04-06, 1323👍, 0💬

How can I split up a string into whitespace-separated fields?
How can I split up a string into whitespace-separated fields? How can I duplicate the process by which main() is handed argc and argv? The only Standard function available for this kind of ``tokenizing'' is strtok, although it can be tricky to use and it may not do everything you want it to. (For in...
2015-08-17, 1321👍, 0💬

How do I send escape sequences to control a terminal or other device?
How do I send escape sequences to control a terminal or other device? If you can figure out how to send characters to the device at all , it's easy enough to send escape sequences. In ASCII, the ESC code is 033 (27 decimal), so code like fprintf(ofd, "\033[J"); sends the sequence ESC [ J . Some prog...
2015-04-20, 1316👍, 0💬

I have a program which mallocs and later frees a lot of memory ...
I have a program which mallocs and later frees a lot of memory, but I can see from the operating system that memory usage doesn't actually go back down. Most implementations of malloc/free do not return freed memory to the operating system, but merely make it available for future malloc calls within...
2016-03-28, 1314👍, 0💬

What is a good way to check for ``close enough'' floating-point equality?
What is a good way to check for ``close enough'' floating-point equality? Since the absolute accuracy of floating point values varies, by definition, with their magnitude, the best way of comparing two floating point values is to use an accuracy threshold which is relative to the magnitude of the nu...
2015-06-26, 1314👍, 0💬

When I call malloc to allocate memory for a pointer which is local to a function ....
When I call malloc to allocate memory for a pointer which is local to a function, do I have to explicitly free it? Yes. Remember that a pointer is different from what it points to. Local variablesare deallocated when the function returns, but in the case of a pointer variable, this means that the po...
2016-03-31, 1309👍, 0💬

What is C language?
What is C language? The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C...
2014-12-31, 1306👍, 0💬

Why wont the Frobozz Magic C Compiler ...
Why won't the Frobozz Magic C Compiler, which claims to be ANSI compliant, accept this code? I know that the code is ANSI, because gcc accepts it. Many compilers support a few non-Standard extensions, gcc more so than most. Are you sure that the code being rejected doesn't rely on such an extension?...
2015-11-25, 1300👍, 0💬

How can I print a character in a printf format string?
How can I print a '%' character in a printf format string? I tried \%, but it didn't work. Simply double the percent sign: %% . The reason it's tricky to print % signs with printf is that % is essentially printf's escape character. Whenever printf sees a %, it expects it to be followed by a characte...
2015-11-09, 1299👍, 0💬

I figured I could use scanf more safely if I checked its ...
I figured I could use scanf more safely if I checked its return value to make sure that the user typed the numeric values I expect: int n; while(1) { printf("enter a number: "); if(scanf("%d", &amp;n) == 1) break; printf("try again: "); } printf("you typed %d\n", n); but sometimes it seems to go...
2015-10-19, 1295👍, 0💬

What does the message warning macro replacement within a string literal mean?
What does the message warning macro replacement within a string literal mean? Some pre-ANSI compilers/preprocessors interpreted macro definitions like #define TRACE(var, fmt) printf("TRACE: var = fmt\n", var) such that invocations like TRACE(i, %d); were expanded as printf("TRACE: i = %d\n", i); In ...
2015-12-14, 1284👍, 0💬

Why isn't a pointer null after calling free? ...
Why isn't a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it's been freed? When you call free, the memory pointed to by the passed pointer is freed, but the value of the pointer in the caller probably remains unchanged, because C's pass-by-value sem...
2016-04-04, 1282👍, 0💬

Here is a good puzzle: how do you write a program which produces its own source code as output?
Here is a good puzzle: how do you write a program which produces its own source code as output? It is actually quite difficult to write a self-reproducing program that is truly portable, due particularly to quoting and character set difficulties. Here is a classic example (which ought to be presente...
2015-01-02, 1279👍, 0💬

If I have a char * variable pointing to the name of a function ...
If I have a char * variable pointing to the name of a function, how can I call that function? Code like extern int func(int, int); char *funcname = "func"; int r = (*funcname)(1, 2); or r = (*(int (*)(int, int))funcname)(1, 2); doesn't seem to work. By the time a program is running, information abou...
2015-02-20, 1275👍, 0💬

Interview question - Order Process Automation
An ecommerce transaction starts on an instance of SAP Hybris at the frontend (browser-based). The order then flows through a bespoke SQL Server based Data Hub, into MS Dynamics 365 (F&amp;O), where the order orchestrated. The flow also includes several batch jobs between the order placement and ...
2020-10-17, 1272👍, 1💬

💬 2020-10-17 FYIcenter.com: If you have the budget, replace all 3 systems with a single end-to-end, fully automated, eCommerce solution. If you want to keep...

What is the right type to use for Boolean values in C? ....
What is the right type to use for Boolean values in C? Is there a standard type? Should I use #defines or enums for the true and false values? Traditionally, C did not provide a standard Boolean type, partly and partly to allow the programmer to make the appropriate space/time tradeoff. (Using an in...
2016-03-02, 1272👍, 0💬

What is the difference between memcpy and memmove?
What is the difference between memcpy and memmove? memmove offers guaranteed behavior if the memory regions pointed to by the source and destination arguments overlap. memcpy makes no such guarantee, and may therefore be more efficiently implementable. When in doubt, it's safer to use memmove. It se...
2015-07-16, 1270👍, 0💬

<< < 157 158 159 160 161 162 163 164 165 166 167 > >>   Sort: Date