Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Posts by alx‭

33 posts
86%
+11 −0
Q&A Why not call nullptr NULL?

It's a long story. Once upon a time, there were three ways to express a null pointer constant: NULL 0 ((char *) 0) This was true at least as far back as Unix V7 (1979). Maybe even further...

posted 2y ago by alx‭  ·  edited 2y ago by alx‭

Answer
84%
+9 −0
Q&A memcmp(3) memory containing invalid values

What does it mean that we can use memcmp(3) on invalid values? ISO C allows comparing an invalid value through memcmp(3), because it doesn't read the value, but rather its representation, and "rea...

2 answers  ·  posted 3y ago by alx‭  ·  last activity 3y ago by Lundin‭

Question c language-lawyer character-type
83%
+8 −0
Q&A Is partial allocation of an object Undefined Behavior?

Is it valid to partly allocate an object, as long as you only use the allocated part of it? #include <stdio.h> #include <stdlib.h> struct s { int i[100]; }; int main(void) {...

1 answer  ·  posted 3y ago by alx‭  ·  last activity 3y ago by Lundin‭

Question c object-lifetime language-lawyer dynamic-allocation
81%
+7 −0
Q&A PGP sign emails sent with git-send-email(1)

How can we use git-send-email(1) to sign patches (emails) with the gpg(1) keyring? I've heard it can be done, but couldn't find anything in the git-send-email(1) documentation nor in a web search.

3 answers  ·  posted 4y ago by alx‭  ·  last activity 2y ago by alx‭

Question git email pgp signing
80%
+6 −0
Q&A array of arrays vs array of pointers to store array of string literals

Let's consider the following code: const char a[][4] = {"aa", "aaa"}; const char *b[] = {"bb", "bbb"}; const char *const c[] = {"cc", "ccc"}; For shared libraries, both b and c arrays require...

0 answers  ·  posted 4y ago by alx‭  ·  edited 4y ago by alx‭

Question c pointers array linker string-literals
77%
+5 −0
Q&A When should I parenthesize macro arguments in C?

I've seen macros use parentheses to enclose its arguments. Most of these make sense, as in #define sum(a, b) ((a) + (b)) The outer prevents the following: #define sum_bad(a, b) (a) + (b) ...

2 answers  ·  posted 3y ago by alx‭  ·  last activity 3y ago by Lundin‭

Question c macros
77%
+5 −0
Q&A Storing more bytes than a union member has, but less than the union size, with memcpy(3)

Let's say we have an object, we store it in a union (into some other narrower type, but with memcpy(3), so it's allowed --I guess--), and then read it from the union via it's original type (so no a...

2 answers  ·  posted 3y ago by alx‭  ·  last activity 3y ago by Lundin‭

Question c strict-aliasing type-punning language-lawyer
77%
+5 −0
Q&A Can freed pointers undergo lvalue conversion?

char *p, *q; p = malloc(1); free(p); q = p; // lvalue conversion Is the last lvalue conversion (= p;) Undefined Behavior or not? We didn't take the address of the local p. C11::6.3.2.1...

2 answers  ·  posted 3y ago by alx‭  ·  last activity 3y ago by Dirk Herrmann‭

Question c pointers language-lawyer
77%
+5 −0
Q&A noreturn function with non-void return type

Is it legal ISO C to declare a function as noreturn with a non-void return type (but of course not actually returning)? As far as I can read from the standard, it seems legal. Example: noreturn ...

1 answer  ·  posted 4y ago by alx‭  ·  edited 4y ago by alx‭

Question c language-lawyer noreturn void
75%
+4 −0
Q&A Extern keyword in C and proper way to use extern variables in embedded systems

And with the same logic, shouldn't the function prototypes in gpio.h also be extern for my source files to see them? Function declarations default to being extern. If you don't specify any st...

posted 2mo ago by alx‭  ·  edited 2mo ago by alx‭

Answer
75%
+4 −0
Q&A Are memccpy(3) or strncpy(3) bad for copying and catenating strings with truncation?

strncpy(3) strncpy(3) was originally invented in Seventh Edition Unix (a.k.a., V7). It was added with one use case in mind: copying a source string into a destination character sequence in a fixe...

posted 2mo ago by alx‭  ·  edited 2mo ago by alx‭

Answer
75%
+4 −0
Q&A Macro to count the number of arguments

Let's say we have a function void f(int argc, ...); where argc is the number of variadic arguments. Can we write a macro of the form #define F(...) f(CNT(__VA_ARGS__), __VA_ARGS__) which...

2 answers  ·  posted 1y ago by alx‭  ·  last activity 1y ago by Lundin‭

Question c c-preprocessor
75%
+4 −0
Q&A Get the name of the remote tracked branch of my local branch for use in script

Can I programmatically get the name of the remote branch which my local branch is tracking? I'm interested in scripting around git-range-diff(1), so that I could do something like this: [alias] ...

1 answer  ·  posted 1y ago by alx‭  ·  last activity 1y ago by Alexei‭

Question git
75%
+4 −0
Q&A Assert that some code is not present in the final binary, at compile or link time.

I'd like to assert that some code can be optimized out, and is not present in the final binary object. #define CONSTANT 0 #if (!CONSTANT) [[landmine_A]] #endif static int foo(void); void...

1 answer  ·  posted 4y ago by alx‭  ·  last activity 4y ago by alx‭

Question c compiler-errors gcc compiler-warnings clang
71%
+3 −0
Q&A How to pipe grep(1) and use compatible exit codes?

I need to wrap grep(1) in a script, and I'd like the script to have an exit code compatible with that of grep(1) --that is, it should return 0 if it found something, 1 if it didn't, and 2 on error-...

1 answer  ·  posted 11mo ago by alx‭  ·  last activity 11mo ago by watchmaker‭

Question bash grep error-handling
71%
+3 −0
Q&A Is strcpy dangerous and what should be used instead?

strcpy(3) can be safe. Some compilers, such as GCC and Clang, use a feature test macro, _FORTIFY_SOURCE, (see feature_test_macros(7) https://man7.org/linux/man-pages/man7/feature_test_macros.7.htm...

posted 3y ago by alx‭

Answer
71%
+3 −0
Q&A Strict aliasing rules and function boundaries

Let's analyze this code, assuming an architecture where the alignment of int64_t is the same as that of double: void bar(double *f, int64_t *j) { *(int64_t *)f = *j; } void foo(void) ...

1 answer  ·  posted 3y ago by alx‭  ·  edited 3y ago by Lundin‭

Question c strict-aliasing type-punning language-lawyer
71%
+3 −0
Q&A How to write a macro that discards the const qualifier, for any type?

How to write a macro that discards the const qualifier, for any type? I hope some combination of typeof and a cast will do, but haven't found the combination. I tried this, without luck: #define...

2 answers  ·  posted 4y ago by alx‭  ·  last activity 4y ago by alx‭

Question c gcc macros casting const-correctness
71%
+3 −0
Q&A Is -isystem a POSIX cc option?

Is -isystem/path/to/sys/includes a standard compiler option, or is it a compiler extension implemented by gcc, clang, and maybe other compilers? Can I rely on its availability? I couldn't find th...

1 answer  ·  posted 4y ago by alx‭  ·  last activity 4y ago by deleted user

Question compiler-options posix cc
70%
+5 −1
Code Reviews stpecpy(): Design a better string copy function that truncates

I was directed a few days ago to a post about a string copy function, which IMO improves the commonly known string copy functions, including strlcpy(3BSD), strlcat(3BSD), and strscpy(9). It define...

2 answers  ·  posted 4y ago by alx‭  ·  last activity 4y ago by alx‭

Question c string string-concatenation strcpy
66%
+2 −0
Q&A Macro to verify that an expression has no side effects at compile time

I'd like to implement a macro strnul(): #define strnul(s) (s + strlen(s)) But that expands and evaluates s twice. I'd like to avoid that. I could do (using GNU extensions) #define strnul(s)...

1 answer  ·  posted 8mo ago by alx‭  ·  last activity 8mo ago by Lundin‭

Question c gcc c-preprocessor
66%
+4 −1
Code Reviews New elementsof() operator

Original problem: https://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c/57537491#57537491 Arrays in C are problematic. They are transformed into pointers too easi...

1 answer  ·  posted 2y ago by alx‭  ·  edited 2y ago by alx‭

Question c array operators
66%
+2 −0
Q&A How to write a macro that discards the const qualifier, for any type?

I developed this macro (using GNU C) similar to C++'s const_cast(). #define const_cast(t, p) \ ({ ...

posted 4y ago by alx‭  ·  edited 4y ago by alx‭

Answer
66%
+2 −0
Q&A Assert that some code is not present in the final binary, at compile or link time.

Calling an undefined function will have that behavior at link time: landmine.c: #ifndef CONSTANT #define CONSTANT 0 #endif #define assert_not_in_binary_if(e) do \ { \ if (e) \ undefi...

posted 4y ago by alx‭  ·  edited 4y ago by alx‭

Answer
66%
+2 −0
Q&A PGP sign emails sent with git-send-email(1)

It can't be done with git-send-email(1), but there's a tool that integrates with it, and is very simple to use: patatt(1). Install the tool: $ sudo apt-get install patatt And then for each rep...

posted 4y ago by alx‭  ·  edited 4y ago by alx‭

Answer