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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:17:18+00:00 2026-06-09T07:17:18+00:00

I am trying to just add print statements to my code to find errors,

  • 0

I am trying to just add print statements to my code to find errors, but cannot seem to get integers or bytes or jints or anything other than a String to show in LogCat.

#define LOG_INFO( info ) __android_log_print( ANDROID_LOG_WARN, "NATIVE CODE", info );


LOG_INFO( "c = " + c );

The result for this is just

c = 

Does anyone know what I am doing wrong, or if this is possible? I have tried jints, ints, chars, jchars, and bytes ( as the type for c ).

  • 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-09T07:17:21+00:00Added an answer on June 9, 2026 at 7:17 am

    The language is C. C does not have a builtin type for a string; strings are really arrays of char or pointers to char. You cannot add neither arrays nor pointers. So there’s no string concatenation by + operator, or by any other operator for that matter. C++ is different, but let’s not go there for now.

    The way __android_log_print() works is similar to Java’s String.format(). To output a character to LogCat, you use the following call:

    __android_log_print(ANDROID_LOG_WARN, "NATIVE CODE", "c=%c", (char)c);
    

    If you want to output several variables – say, a char and an int, the call would be:

    int n;
    __android_log_print(ANDROID_LOG_WARN, "NATIVE CODE", "c=%c, n=%d", (char)c, n);
    

    __android_log_print is a variadic function – it takes a variable number of arguments (but no less than three), with unknown types beyond the first three. The types of the extra arguments are deduced from the format specifiers in the format string – the %-sequences. %c means char, %d means int, %s is char string and so forth, look it up.

    This is the printf pattern, used throughout the C world. It does not easily lend itself to macro-izing, unless you’re willing to introduce separate macros for outputting 0, 1, 2, etc. parameters. That way, it might look like this:

    #define LOG_INFO0( info ) __android_log_print( ANDROID_LOG_WARN, "NATIVE CODE", info );
    #define LOG_INFO1( info, p1 ) __android_log_print( ANDROID_LOG_WARN, "NATIVE CODE", info, p1 );
    #define LOG_INFO2( info, p1, p2 ) __android_log_print( ANDROID_LOG_WARN, "NATIVE CODE", info, p1, p2 );
    
    //...
    LOG_INFO("c=%c", (char)c);
    

    I’m deliberately avoiding the thorny issue of character type conversion here; for the %c format specifier, the function expects a parameter of type char which is not the same as jchar. For jchar’s that are non-ASCII characters, this snippet will print garbage.

    Just FYI: the correspondence between Java types and C types is not straightforward, and it’s actually somewhat platform-dependent. For the purposes of printing, you need to carefully watch. So:

    • jchar is not char; it’s unsigned short. Shortening to char loses data.
    • jlong is not long, it’s long long (64-bit integer)
    • jboolean is signed char (no boolean datatype in C)
    • jbyte is signed char (no byte datatype in C)
    • jint is int (on Android)
    • jfloat is float
    • jshort is short
    • jdouble is double
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just trying to test for equality in this piece of code, but getting a
Today, while I was trying to write code to just add and subtract the
I'm just trying to add 2 columns to customer table alter table CUSTOMER ADD
I am trying a very simple override. I just want to add one line
I'm just new to Zend and currently I'm trying to add a dash(-) to
I am trying to add/remove UILabels to a ScrollView. The adding takes place just
Just trying to get diff to work better for certain kinds of documents. With
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to get my head around what can happen when things go wrong
I'm testing some code(trying to make it faster but also trying to understand the

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.