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‭

26 posts
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 2y ago by alx‭  ·  last activity 2y ago by Lundin‭

83%
+8 −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 2mo ago by alx‭  ·  edited 26d ago by alx‭

Answer
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 2y ago by alx‭  ·  last activity 2y ago by Lundin‭

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 2y ago by alx‭  ·  last activity 8mo 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 2y ago by alx‭  ·  edited 2y ago by alx‭

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 3y ago by alx‭  ·  edited 3y ago by alx‭

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 1y ago by alx‭  ·  last activity 1y 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 1y ago by alx‭  ·  last activity 1y ago by Lundin‭

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 1y ago by alx‭  ·  last activity 1y ago by Dirk Herrmann‭

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 2y ago by alx‭  ·  edited 2y ago by Lundin‭

71%
+3 −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 2y ago by alx‭  ·  last activity 2y ago by alx‭

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 2y ago by alx‭  ·  last activity 2y ago by alx‭

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 1y ago by alx‭

Answer
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 2y ago by alx‭  ·  last activity 2y ago by deleted user

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 3y ago by alx‭  ·  last activity 2y ago by alx‭

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 2y ago by alx‭  ·  edited 2y 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 2y ago by alx‭  ·  edited 2y 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 2y ago by alx‭  ·  edited 2y ago by alx‭

Answer
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 4mo ago by alx‭  ·  edited 4mo ago by alx‭

Question c array operators
60%
+4 −2
Q&A Is `git pull` dangerous?

I heard git pull is dangerous. Is it really dangerous? If so, why or how is it dangerous? Are there any flags that mitigate or remove the danger? What are the alternatives if it...

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

Question git
60%
+4 −2
Q&A Which platforms return a non-null pointer on malloc(0)

What is the portability of malloc(0);? Which platforms return NULL without setting errno? Which platforms return a non-null pointer? Do any platforms have some other behavior?

2 answers  ·  posted 3mo ago by alx‭  ·  last activity 2mo ago by Alexei‭

Question c malloc
57%
+2 −1
Q&A How to keep git blame ignored commits up to date?

[Disclaimer: This is an alternative workaround, and not really answering your question.] When blaming files in a git repository in which I am working at the moment, I usually blame from the master...

posted 17d ago by alx‭  ·  edited 17d ago by alx‭

Answer
54%
+4 −3
Q&A Is `git pull` dangerous?

git pull is dangerous, but not a security problem. The only danger is that it's difficult or inconvenient (but not impossible) to recover to the state prior to the pull, if it would be necessary. ...

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

Answer
50%
+1 −1
Code Reviews stpecpy(): Design a better string copy function that truncates

After addressing @Lundin 's suggestions: Implemented in terms of libc functions for performance. const correctness style improvements I have a few more that I realized after trying to repla...

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

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

git-send-email(1) uses sendmail(8) as the MTA by default. However, this can be changed by passing the --sendmail-cmd option. $ man git-send-email | sed -n '/--sendmail-cmd=/,/^$/p' --sendma...

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

Answer