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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:18:43+00:00 2026-05-17T15:18:43+00:00

Does anyone know how to dynamically get all the variables values passed into a

  • 0

Does anyone know how to dynamically get all the variables values passed into a function for the sake of logging ?

I’m looking for a simple way (like using a compiler macro) to be able to log the function, and the variable values passed into it (which will then be written to a log file so we can easily find inputs that cause functions to crash)

I’ve been trying

#define NFDebug( s, ... ) NSLog( @"DEBUG: %s: %@", __PRETTY_FUNCTION__, \
[NSString stringWithFormat:(@"%@"), ##__VA_ARGS__] )

,which gives everything, BUT the variables values

  • 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-17T15:18:43+00:00Added an answer on May 17, 2026 at 3:18 pm

    I use something like this:

    #ifdef YOUR_DEBUG_ENABLER_SYMBOL_ONLY_SET_IN_DEBUG_BUILDS
    #define DEBUG_ONLY(_code_) _code_
    #else
    #define DEBUG_ONLY(_code_)
    #endif
    
    #define DebugLog(_str, ...) DEBUG_ONLY(NSLog(@"%s: " _str, __func__, ## __VA_ARGS__))
    

    Note that there is no comma before the _str in the NSLog – this means the string you use in your calling code is appended (by the compiler) to the “%s: ” string to become a composite format string for the NSLog. Whatever parameters you want to print can be included in your passed in format string. The %s applies to the _ _ func _ _ and your _str applies to the rest of the passed in variables:

    float f;
    int i;
    NSString* s;
    // Initialise f, i, and s to something
    ...
    // Log the values only when in debug mode, with function name auto-prepended
    DebugLog(@"float is: %f - int is: %d - string is: %@", f, i, s);
    

    This has the advantage that you can log whatever text and variables you want, conditionally on debug, and with the function name automatically prepended onto the output.

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

Sidebar

Related Questions

Lets suppose I am trying to analyze an algorithm and all I can do
I'm dynamically creating a select node with option nodes inside. The code works fine
I am having a problem assigning a control to dynamically added elements (inside the
I'm generating PDFs dynamically using PHP and PDFlib and some of the fields require
I have a CWnd window which I create dynamically, and it seems that the
Using Ruby 1.9.2 Problem Compare the content, not the results, of two procs. I
I have a div set to contentEditable and styled with white-space:pre so it keeps
I have two applications. In one application the web browser control shows a flash
I have an Administrator that needs a dynamic form generator with layout capabilities on

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.