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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:01:36+00:00 2026-05-27T18:01:36+00:00

SWIG converts the below unsigned char array (id) to short[]. On the C side,

  • 0

SWIG converts the below unsigned char array (“id”) to short[]. On the C side, the id attribute of the sender_id_t_ struct is a pointer to an array that contains alphanumeric data like “TEST123-E”. I suppose you could loop over short[] (sender_id_t_.getId()) and cast each element to a char and concatenate to build a Java String. I’m wondering if their is a better and simpler way of handling this situation?

C Header File:

#define SAMPLE_ID_SIZE_V1 32
#define SAMPLE_ID_SIZE SAMPLE_ID_SIZE_V1

typedef unsigned char sample_id_v1_t[SAMPLE_ID_SIZE];
typedef sample_id_v1_t sample_id_t;

struct sample_sender_id_t_ {
    sample_id_t           id;
    uint32_t              idx;
};
typedef struct sample_sender_id_t_ sample_sender_id_t;

SWIG.i:

%rename (Sample) sender_id_t_;
struct sender_id_t_ {
    unsigned char id_v1_t[32]      id;
    uint32_t   phy_idx;
};

Exception:

 [exec] test_wrap.c: In function `TestJNI_Sample_1id_1set':
 [exec] test_wrap.c:826: error: cast specifies array type
 [exec] test_wrap.c:829: error: incompatible types in assignment
 [exec] test_wrap.c:832: error: `jarr2' undeclared (first use in this function)
  • 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-27T18:01:37+00:00Added an answer on May 27, 2026 at 6:01 pm

    It gets treated as an array of short because of the unsigned of the type, which makes the largest value too large to fit in a (signed) byte or char. If you want to force it to be treated a String you can use %apply to use the normal String typemaps, something like:

    %module test
    
    %rename (Sample) sender_id_t_;
    %apply char * { unsigned char id[32] };
    
    struct sender_id_t_ {
        unsigned char id[32];
        uint32_t   phy_idx;
    };
    

    (I had to fix some syntax in your struct, that was a bit odd).

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

Sidebar

Related Questions

It seems that SWIG pointer-casting is broken : *(int **)&jresult = result; // shenanigans
I'm trying to write a SWIG wrapper for a C library that uses pointers
I've been trying to use SWIG to wrap around a simple library that uses
I have a python module that imports a module generated with swig. When I
OK so I have a C++ class that is exposed to Lua using SWIG.
SWIG seems to be generating incorrect bindings for converting a struct field of type
I notice that Swig provides a whole host of functions to allow for typecasting
I have a class that is wrapped with swig, and registered with lua. I
I'm testing swig, and I found that SWIG's vcxproj file runs the mt.exe to
Our C++ lib works fine with Python2.4 using Swig, returning a C++ char* back

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.