OcttKB/Wiki-OcttKB/tiddlers/Normal/_C Language.tid

39 lines
5.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

created: 20231029134919585
creator: Octt
modified: 20231224151327804
modifier: Octt
tags:
title: C Language
<<^wikipediaframe C_Language>>
* [[reassign struct in C|https://stackoverflow.com/questions/10298070/reassign-struct-in-c]] (meaning reassigning all fields at a time); the feature is part of compound literals, sadly only supported in C99+, won't work before that and it's not easy to guess why without knowing this
* [[How to copy arrray to array using memcpy() in C|https://stackoverflow.com/a/15685912]] --- //you should allocate memory for tmp with size = sizeof(a). And then memcpy with size = sizeof(a)//
* [[Reading command line parameters|https://stackoverflow.com/questions/5157337/reading-command-line-parameters]]
* [[Why do many functions that return structures in C, actually return pointers to structures?|https://softwareengineering.stackexchange.com/questions/359408/why-do-many-functions-that-return-structures-in-c-actually-return-pointers-to-s]]
* [[Passing by reference in C|https://stackoverflow.com/questions/2229498/passing-by-reference-in-c]] --- "C does not support passing a variable by reference"... //Passing a pointer ''is'' passing-by-reference. This seems to be one of those facts that "savvy" C programmers pride themselves on. Like they get a kick out of it. "Oh you might THINK C has pass-by-reference but no it's actually just the value of a memory address being passed harharhar". Passing by reference literally just means passing the memory address of where a variable is stored rather than the variable's value itself [...]//
* [[Pointers in C: when to use the ampersand and the asterisk?|https://stackoverflow.com/questions/2094666/pointers-in-c-when-to-use-the-ampersand-and-the-asterisk#2094715]]
** Related: [[error: invalid type argument of unary * (have int)|https://stackoverflow.com/questions/5455866/error-invalid-type-argument-of-unary-have-int#5455962]], this happens when using `*` against a value instead of a pointer, since you can't dereference a value from a value.
* [[What is a "callback" in C and how are they implemented?|https://stackoverflow.com/questions/142789/what-is-a-callback-in-c-and-how-are-they-implemented/142809#142809]] (function pointers)
** [['declared as a function' in C|https://stackoverflow.com/questions/23329261/declared-as-a-function-in-c#23329274]] --- function pointers in structs must be declared with the syntax `type (functionName*)( type arg1, ... )`
* [[Where should I prefer pass-by-reference or pass-by-value?|https://stackoverflow.com/questions/4986341/where-should-i-prefer-pass-by-reference-or-pass-by-value]] --- (performance-wise) //"here's the simple rule: pass by reference when the value is large."//
** [[When should I pass or return a struct by value?|https://stackoverflow.com/questions/30980759/when-should-i-pass-or-return-a-struct-by-value]]
* [[Directly assigning values to C Pointers|https://stackoverflow.com/questions/17665793/directly-assigning-values-to-c-pointers]]
* [[strcpy vs. memcpy|https://stackoverflow.com/questions/2898364/strcpy-vs-memcpy]] --- //strcpy stops when it encounters a NUL ('\0') character, memcpy does not//, aka as the names suggest often strcpy is perfect for strings while for generic data memcpy could be needed.
* [[ISO C90 forbids mixed declarations and code in C|https://stackoverflow.com/questions/13291353/iso-c90-forbids-mixed-declarations-and-code-in-c]] --- old C standards required that new variables can be declared only before any other actual instruction in a scoped block, e.g. only at the top of a function
* [["Multiple definition", "first defined here" errors|https://stackoverflow.com/questions/30821356/multiple-definition-first-defined-here-errors]] --- error that can arise in multiple cases
* [[Creating empty function macros|https://stackoverflow.com/questions/9187628/empty-function-macros]] --- only safe way is `#define SomeFunction(arg) ((void)0)`
** [[C macros, what's the meaning of ((void)0)?|https://stackoverflow.com/questions/61157541/c-macros-whats-the-meaning-of-void0]]
* [[How to use "else if" with the preprocessor #ifdef?|https://stackoverflow.com/questions/68696585/how-to-use-else-if-with-the-preprocessor-ifdef]] --- the only widely-supported way is: `#if defined(X)`...`#elif defined(Y)`...`#else`...`#endif`
** "compound conditionals" are supported, eg. `#if defined(X) || (defined(Y) && defined(Z))`...
* [[How to enforce C89-style variable declarations in gcc?|https://stackoverflow.com/questions/3099813/how-to-enforce-c89-style-variable-declarations-in-gcc#3099874]] --- for some things of this goal, just the flags `-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement` are needed, I would guess.
* [[Good C-coding style for multiple lines if conditions|https://stackoverflow.com/questions/29328923/good-c-coding-style-for-multiple-lines-if-conditions]]
* [[How to get the current directory in a C program?|https://stackoverflow.com/questions/298510/how-to-get-the-current-directory-in-a-c-program]] --- (`getcwd(...)`)
* [[C Program to list all files and sub-directories in a directory|https://www.geeksforgeeks.org/c-program-list-files-sub-directories-directory/]]
* [[How to read the content of a file to a string in C?|https://stackoverflow.com/a/174552]]