Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ExcessBLarg!
Sep 1, 2001

Ola posted:

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?
Dear lord no. I mean, the tooling is better than it was 30 years ago but it's not omniscient.

If you have the luxury of working on a brand new project in C (but, not in some other language for some weird reason) and you're very disciplined, and sufficiently experienced, you can write reasonably safe code. It's not automatic and you're almost always better off using another language where the safety checks are built-in. Even here, crusty old APIs will bite you because they often predate best practices and mangling things to make them work reasonably takes effort. Add in an actual legacy codebase and the problem gets a few orders of magnitude worse.

For the hell of it I turned -Wextra on again for a code I've been working on recently and the two things that bite me are unused parameters, which I get why it warns you about them but sometimes APIs genuinely contain unneeded/reserved parameters, and a bunch of signed/unsigned integer comparisons where I'm intentionally exploiting unsigned integer promotion.

Adbot
ADBOT LOVES YOU

Xerophyte
Mar 17, 2008

This space intentionally left blank

ExcessBLarg! posted:

For the hell of it I turned -Wextra on again for a code I've been working on recently and the two things that bite me are unused parameters, which I get why it warns you about them but sometimes APIs genuinely contain unneeded/reserved parameters, and a bunch of signed/unsigned integer comparisons where I'm intentionally exploiting unsigned integer promotion.

The "usual" way people deal with this if they want the unused parameters warning enabled is to #define UNUSED(x) (void)(x) and start functions with unused parameters as

C++ code:
void f(void* not_used) {
  UNUSED(not_used);
  // ...
}
to explicitly mark the parameter as named, yet unused. This may technically have side-effects in some corner cases, like when the parameter maps to some volatile IO were reading it does something. There are other possible solutions: you can use __attribute__((unused)) if your compiler has it (an inline __pragma(warning(suppress:4100)) does the same on MSVC) and in C++ you can of course just leave the parameter unnamed. The cast to void pattern is, for better or worse, the standard solution.

more falafel please
Feb 26, 2005

forums poster

The project I'm on now has an UNUSED() macro but it's being deprecated in favor of just doing (void) casts for some reason. Seems to me like keeping it easily searchable is reason enough to stick with the macro solution.

ExcessBLarg!
Sep 1, 2001
Thankfully it's not a default warning with -Wall.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


C and C++ only complains about a parameter being unused if you give it a name. So you'll get a warning for
code:
int foo(int bar)
{
    return 0;
}
but
code:
int foo(int)
{
    return 0;
}
is completely fine.

ultrafilter fucked around with this message at 16:46 on Feb 24, 2022

more falafel please
Feb 26, 2005

forums poster

ultrafilter posted:

C and C++ only complains about a parameter being unused if you give it a name. So you'll get a warning for
code:
int foo(int bar)
{
    return 0;
}
but
code:
int foo(int)
{
    return 0;
}
is completely fine.

Doesn't work with conditional compilation (for different platforms, features, debug) unless you also put the function definition header in the #ifdef.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


What #ifdef?

CPColin
Sep 9, 2003

Big ol' smile.
Not much, what #ifdef with you?

FlapYoJacks
Feb 12, 2009

ultrafilter posted:

What #ifdef?

I don’t know, what’s #ifdef with you?

Edit: gently caress!

more falafel please
Feb 26, 2005

forums poster

ultrafilter posted:

What #ifdef?

code:
void foo(int bar, int baz)
{
#ifdef _WIN32
    do_a_thing(bar, baz);
#else
    do_a_different_thing(bar);
#endif
}
If I wanted to not name baz, I'd have to use another #ifdef/#else around the function definition header.

There's a good argument to be made that you shouldn't use ifdefs this granularly, but this type of code is all over the place. Avoiding it can also lead to tons of lovely code duplication.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


code:
int foo(int) {
    return 0;
}

int main() {
    return foo(5);
}
I just ran this through a few clang, gcc and msvc variants on godbolt.org and they all handled it with no problems.

Volte
Oct 4, 2004

woosh woosh

ultrafilter posted:

code:
int foo(int) {
    return 0;
}

int main() {
    return foo(5);
}
I just ran this through a few clang, gcc and msvc variants on godbolt.org and they all handled it with no problems.
Now use that parameter in the body of foo, but only on Windows

CPColin
Sep 9, 2003

Big ol' smile.

DoomTrainPhD posted:

I don’t know, what’s #ifdef with you?

Edit: gently caress!

Shoulda put an #ifndef on your post :cool:

Kazinsal
Dec 13, 2011



https://twitter.com/zdimension_/status/1497004313427722240

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Volte posted:

Now use that parameter in the body of foo, but only on Windows

At that point I'd be looking at a wrapper function that can be easily inlined.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

ultrafilter posted:

At that point I'd be looking at a wrapper function that can be easily inlined.

You're gonna have to be more specific about this because the obvious way of writing such a wrapper function runs into literally the exact problem that everyone's discussing.

Or do you mean you'd manually inline this function and its own (potentially complex) if-defs in every place that it's called?

qsvui
Aug 23, 2003
some crazy thing

ultrafilter posted:

C and C++ only complains about a parameter being unused if you give it a name.

:actually: this behavior doesn't look standard on C (until C23), source cppreference:
C code:
int f(int, double); // OK
int g(int a, double b); // also OK
// int f(int, double) { return 1; } // Error: definition must name parameters
// This definition is allowed since C23

Xarn
Jun 26, 2015

Ola posted:

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?

:lmao:



:suicide:

Presto
Nov 22, 2002

Keep calm and Harry on.
C is easy and safe already, if you know what you're doing. :smug:

OddObserver
Apr 3, 2009

Presto posted:

C is easy and safe already, if you know what you're doing. :smug:

No human knows what they are doing. Maybe things like your avatar do.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Who even needs a debugger? Just write your code correctly the first time. :dukedog:

QuarkJets
Sep 8, 2008

Quebec Bagnet posted:

Who even needs a debugger? Just write your code correctly the first time. :dukedog:

My code is always correct, for certain definitions of correct

BigPaddy
Jun 30, 2008

That night we performed the rite and opened the gate.
Halfway through, I went to fix us both a coke float.
By the time I got back, he'd gone insane.
Plus, he'd left the gate open and there was evil everywhere.


My code always does exactly what I want it do. Just because it doesn’t do what you want it to sounds like your problem.

boo_radley
Dec 30, 2005

Politeness costs nothing

nielsm posted:

NaN by definition represents an unknowable value, so you have to assume that two NaN values are different.
Usually SQL NULL represents the absence of a value, while NaN represents that a value is present but unknowable.
this makes it sound like a biblical angel

NaN (a floating ball of eyes and wings) " be not afraid... but I have looked at your code so ... be somewhat ashamed"

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

Ola posted:

A dumb question: Isn't there huge amounts of user friendly tooling that makes C easy and safe by now?
Sounds like a huge amount of precious cycles wasted to me!

Kazinsal
Dec 13, 2011



Someone in this thread once described C++ as a language made of byzantine footguns. By backwards extension, C is a language made for creating byzantine footguns.

Tei
Feb 19, 2011

Quebec Bagnet posted:

Who even needs a debugger? Just write your code correctly the first time. :dukedog:

Somebody
https://twitter.com/coil780/status/1497245075977375746


The perpetrator, in case he have not deleted his twitter account now
https://twitter.com/allenholub/status/1496326760719216643

redleader
Aug 18, 2005

Engage according to operational parameters
writing bugs in the first place? pathetic. unprofessional

Itaipava
Jun 24, 2007
I love Holub, he gives such bad takes so frequently that I can't decide if a) he's a total maniac b) he likes to rile people up because he's a "software influencer" and knows that this increases engagement with his brand or c) this "you don't need testers, actually" take works well with management at the companies he consults for and never sticks around in long enough to witness the consequences of following his guidance.

Probably all three I guess

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Itaipava posted:

I love Holub, he gives such bad takes so frequently that I can't decide if a) he's a total maniac b) he likes to rile people up because he's a "software influencer" and knows that this increases engagement with his brand or c) this "you don't need testers, actually" take works well with management at the companies he consults for and never sticks around in long enough to witness the consequences of following his guidance.

Probably all three I guess

Management consultants exist to tell management what they want to hear. If this guy has a particular brand, they're expecting to get particular feedback. So yeah. All three sounds right.

Itaipava
Jun 24, 2007
I like to read his blog posts as performance art. For this bugtracking thing he posted one where he starts with:

quote:

You do not need a bug tracking system. In fact, a bug tracking system is a symptom of a deeper problem—insufficient focus on quality.

...and then when a reader leaves a comment calling him out and pointing out that his wordpress install has the wrong time he replies with:



Bugs for thee but not for me

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
Dude just doesn't realize that Twitter is his bug tracker now. He can CLOSE: WONTFIX every bug if he wants, but that's still where they're getting reported.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The "file a ticket and maybe we'll schedule it next quarter" approach to dealing with bugs is pretty garbage and the focus on shipping features on schedule over fixing bugs asap is a big part of why software is so awful, but even when working on small self-contained things I've accumulated a list of bugs to fix while in the process of fixing the first bug I found plenty of times.

Doom Mathematic
Sep 2, 2008
Even if you do fix every bug immediately on discovering it - which you can't - there are still a half-dozen excellent reasons that you still need to track that work.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
Let alone the reasons you may not bother fixing bugs.

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
Side question, is using github as a bug tracker feasible? Im planning on eventually attemtping to get my project adopted and am wondering if a Google form or Github would be better for a "Bug Report" with a bunch of decidedly older and non tech savvy walking ID10T errors.

YanniRotten
Apr 3, 2010

We're so pretty,
oh so pretty

D34THROW posted:

Side question, is using github as a bug tracker feasible? Im planning on eventually attemtping to get my project adopted and am wondering if a Google form or Github would be better for a "Bug Report" with a bunch of decidedly older and non tech savvy walking ID10T errors.

GitHub has an issue tracker so I'd say... use that over a Google form. If you have to go out of band (repo in GitHub, bugtracking elsewhere) it should be for something more fully featured.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
GitHub issues are a totally reasonable way to track bugs, but you'll probably still want some other way for non-technical end users to ask questions and report problems.

YanniRotten
Apr 3, 2010

We're so pretty,
oh so pretty
Yeah depending on audience, I wouldn't tell them they should create their own issues or give them anything other than read-only access to your bugtracker.

If you think that would result in pure garbage they should chat with you, you can tell them what issue to watch and its priority if it's a real problem.

Adbot
ADBOT LOVES YOU

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
Oh, it would be reporting only. Im the sole developer of a pet project to improve company wide workflow, itself an outgrowth of a mountain of VBA I wrote to do the same in excel and months of work I spent on an Access app a few years back. Nobody not at least as competent in Python as i am would touch my code, which excludes probably 99% of the company.

Reports only, mitts off my loving code :v:


EDIT: i also considered a gmail for the app to send out reset emails and such, perhaps another one for bug reports or the same one and I do it myself on Github. Not that I expect bugs. It's fairly simple stuff on the backend and im testing wacky edge cases as I go along, but poo poo happens.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply