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

  • Home
  • SEARCH
  • 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 3345848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:14:03+00:00 2026-05-18T01:14:03+00:00

I was stepping through some simple Objective-C code with gdb (inside of Xcode) and

  • 0

I was stepping through some simple Objective-C code with gdb (inside of Xcode) and noticed something strange. Here is the relevant snippet:

NSString *s = nil;
int x = (s == nil);

As I’d expect, the value of x after these two lines is 1. Strangely, if I try something similar in gdb, it doesn’t work the same:

(gdb) print ret
$1 = (NSString *) 0x0
(gdb) print (int)(ret==nil)
$2 = 0
(gdb) print nil
$3 = {<text variable, no debug info>} 0x167d18 <nil>

It seems like gdb has some definition for nil other than what objective-C uses (0x0). Can someone explain what’s going on here?

  • 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-05-18T01:14:03+00:00Added an answer on May 18, 2026 at 1:14 am

    When your code is being compiled, nil is a preprocessor constant defined to be either __null (a special GCC variable that serves as NULL), 0L, or 0:

    <objc/objc.h>
    #ifndef nil
    #define nil __DARWIN_NULL /* id of Nil instance */
    #endif
    
    <sys/_types.h>
    #ifdef __cplusplus
    #ifdef __GNUG__
    #define __DARWIN_NULL __null
    #else /* ! __GNUG__ */
    #ifdef __LP64__
    #define __DARWIN_NULL (0L)
    #else /* !__LP64__ */
    #define __DARWIN_NULL 0
    #endif /* __LP64__ */
    #endif /* __GNUG__ */
    #else /* ! __cplusplus */
    #define __DARWIN_NULL ((void *)0)
    #endif /* __cplusplus */
    

    So, where does the nil that gdb picks up at runtime come from? You can tell from the message gdb gives that nil is the name of a variable located at that address:

    (gdb) p nil
    $1 = {<text variable, no debug info>} 0x20c49ba5da6428 <nil>
    (gdb) i addr nil
    Symbol "nil" is at 0x20c49ba5da6428 in a file compiled without debugging.
    

    Its value, unsurprisingly, turns out to be 0:

    (gdb) p *(long *)nil
    $2 = 0
    (gdb) x/xg nil
    0x20c49ba5da6428 <nil>: 0x0000000000000000
    

    Where does this variable come from? GDB can tell us:

    (gdb) i shared nil
      3 Foundation        F -                 init Y Y /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation at 0x20c49ba5bb2000 (offset 0x20c49ba5bb2000)
    

    Indeed, when we check the symbols defined in Foundation, we find nil:

    $ nm -m /System/Library/Frameworks/Foundation.framework/Foundation | grep nil$
    00000000001f4428 (__TEXT,__const) external _nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was stepping through some C/CUDA code in the debugger, something like: for(uint i
In the code below, when I examine the Chars variable while stepping through the
I have written some simple and working assembly code on 8085 trainer hardware. But
I have a simple control with code to add some paths. When I add
I'm after some advice on the most efficient approach to stepping through a list
first question here. I am trying to learn python by stepping through project euler,
You're stepping through C/C++ code and have just called a Win32 API that has
Stepping through the debugger, the BBox object is okay at the entry of the
I would like to implement or use functionality that allows stepping through a Table
I have a project in Java that I am stepping through and when I'm

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.