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 7800683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:43:01+00:00 2026-06-02T00:43:01+00:00

For example: debug_print(foobar); // prints out: foobar is (hello, world) debug_print(i * 27); //

  • 0

For example:

debug_print(foobar);     // prints out:  foobar is (hello, world)
debug_print(i * 27);     // prints out:  i * 27 is 54

in other words, print out the variable or the expression literally first, and then dump its values out.

It doesn’t need to be in this form. It can be called as a string too:

debug_print("foobar");     // prints out:  foobar is (hello, world)
debug_print("i * 27");     // prints out:  i * 27 is 54

Update: or how can it be written if it is not built in?

  • 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-02T00:43:03+00:00Added an answer on June 2, 2026 at 12:43 am

    You can use the macro

    #define debug_print(expr...) NSLog(@"%@ is %@", @#expr, (expr))
    

    As you can see, the NSLog format string expects a %@ (object), so you need to use a variant for integers:

    #define debug_printI(expr...) NSLog(@"%@ is %d", @#expr, (expr))
    

    EDIT:

    There is a way to use a single macro and have it work with all types: use @encoding to find the type.

    NSString *print_debug_format_for_type(const char *encoding) {
    switch (encoding[0]) {
        case '@': return @"%@ is %@";
        case '*': return @"%@ is %s";
    
        case 'f': return @"%@ is %f";
        case 'd': return @"%@ is %f";
    
        case 'q': return @"%@ is %qi";
        case 'Q': return @"%@ is %qu";
    
        case 'c':
        case 'i':
        case 's':
        default: return @"%@ is %d";
    }
    }
    
    #define debug_print(expr...) ({                                 \
    typedef __typeof__(expr) t;                                     \
    NSLog(print_debug_format_for_type(@encode(t)), @#expr, (expr)); \
    })
    

    With this, you can use debug_print anywhere with (almost) any type, as long as it’s in the print_debug_format_for_type. The encodings that are passed in (from @encode) can be found here [apple docs], and the formats for the format string can be found here [also apple docs]. As is, this works with any object, c-style string, integer, float, or double expression.

    (minor caveat: the ObjC BOOL type is actually a typedef’d char, so if you print_debug a boolean expression it will say it is a 1 or 0. While this works, it also means that if you print_debug a char expression, it will say it is the ascii number of the char. To change this behavior (and break BOOL printing), change case ‘c’ to return @"%@ is %c".

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

Sidebar

Related Questions

I'm trying to use lua for windows - SciTE Simply example such as Print(hello)
When I use the __FUNCTION__ macro/variable to print out debugging information, there seems to
Example of a $text variable: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
Example: puts <<BLOCK ... BLOCK with BLOCK being any other identifier that doesn't clash
// example-1: GetStringUTFChars() public class Prompt { // native method that prints a prompt
I want to print lots of debug log prints in C++. Is there a
I'm trying to print out debug statements when some third party code changes a
I am writing a debug function, which prints a variable name, and its value.
sometimes i use debug code to alert something in javascript (for example, matching something
In the following code example, the Debug.Assert will fail. If the AsImplementedInterfaces() extension is

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.