Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:44+00:00 2026-06-13T18:41:44+00:00

Would this be a valid use of NULL in C or are there other

  • 0

Would this be a valid use of NULL in C or are there other ways to solve this problem that are preferred?

// Send data
// cb_push returns NULL if it is successful
char uart_send(char c) {
    void* ret = cb_push(w_buffer, &c);
    if (ret != NULL) return c;

    SETBIT(UCSR0B, UDRIE0);
    return NULL;
}

In Java I would do like this, sort of, but in C I don’t know what is good practice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:41:45+00:00Added an answer on June 13, 2026 at 6:41 pm

    It’s not really defined and there are different approaches depending on the library and/or function you’re using. In general, there’s no way to differentiate between 0 and NULL (in fact, NULL is usually just a preprocessor macro expanding to 0).

    In general, the following possibilities are used, sometimes even matched within one library depending on the usage:

    • If a pointer is returnd, a return value of 0 usually indicates some kind of error.
    • Functions with status codes (or main entry points) usually return 0 in case there hasn’t been any error.
    • There are functions returning 0 if something hasn’t been successfull (i.e. they return a boolean value).
    • Some stdlib string functions return an “absurd” value in case there has been an error (or nothing found). For example, std::string::find() will return -1 if the sub string couldn’t be found. This is however wrapped/hidden behind a constant named value (std::string::npos) to avoid throwing around “magic values”.

    Is there a perfect way? I don’t think so, but it really depends on the specific use case. If you return a pointer, returning 0 in case of a mistake is just perfect. If you’re returning status codes, I’d go with either macros (similar to windows API) or enums. Don’t even worry about any specific values – only use the names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would this be the correct way of declaring that an XML element Cluster contains
I have read that you can do it, but would this really improve performance
I'm interested to know if there is an interface that I can use to
I frequently have code that looks something like this: if (itm != null) {
Use Case: There is a web service posted as https://a.b.c.d/zz?wsdl What i would like
Would this be a proper way to dispose of a BackGroundWorker? I'm not sure
Why would this work timeout 10s echo foo bar # foo bar but this
For a login system in php would this be a suitable outline of how
In a single paged application, would this be the best way to bind and
I'd like to enable SVNAutoversioning for one repository only. Would this work? <Location /repos/>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.