RajSanpui
RajSanpui

Reputation: 12094

Why do I get error in printing this structure pointer?

My library (amqp C library) has a .h file called amqp.h which has this:

typedef struct amqp_connection_state_t_ *amqp_connection_state_t;

struct amqp_connection_state_t_ {
  amqp_pool_t frame_pool;
  amqp_pool_t decoding_pool;

  amqp_connection_state_enum state;

  int channel_max;
  int frame_max;
  int heartbeat;
  amqp_bytes_t inbound_buffer;

  size_t inbound_offset;
  size_t target_size;

  amqp_bytes_t outbound_buffer;

  int sockfd;
  amqp_bytes_t sock_inbound_buffer;
  size_t sock_inbound_offset;
  size_t sock_inbound_limit;

  amqp_link_t *first_queued_frame;
  amqp_link_t *last_queued_frame;

  amqp_rpc_reply_t most_recent_api_result;
};

I am trying to print the above values of the structure in my local test program:

amqp_connection_state_t state;
state = conn->getConnectionState( );
printf("Connection state values\n");
printf("Channel max: %d", state->channel_max);
printf("frame max: %d", state->frame_max);
printf("sockfd: %d", state->sockfd);

In turn I am getting the following compilation errors:

amqpoc.cpp: In function âvoid* con(void*)â:
amqpoc.cpp:85: error: invalid use of incomplete type âstruct amqp_connection_state_t_â
../common/amqp.h:294: error: forward declaration of âstruct amqp_connection_state_t_â
amqpoc.cpp:86: error: invalid use of incomplete type âstruct amqp_connection_state_t_â
../common/amqp.h:294: error: forward declaration of âstruct amqp_connection_state_t_â
amqpoc.cpp:87: error: invalid use of incomplete type âstruct amqp_connection_state_t_â
../common/amqp.h:294: error: forward declaration of âstruct amqp_connection_state_t_â
amqpoc.cpp:88: error: invalid use of incomplete type âstruct amqp_connection_state_t_â
../common/amqp.h:294: error: forward declaration of âstruct amqp_connection_state_t_â

Where is the issue?

Upvotes: 0

Views: 272

Answers (2)

nos
nos

Reputation: 229204

struct amqp_connection_state_t_ is for internal use. You are not supposed to access it directly. The amqp_connection_state_t type your code deals with is an opaque handle

So, it appears your post isn't entirely truthful, the struct amqp_connection_state_t_ declaration is NOT in the header file you include, it is in the amqp_private.h file, but you include amqp.h

If you want to get the channel_max , there is an access function for that:

  printf("Channel max: %d", amqp_get_channel_max(state));

The ->sockfd member is exposed with the amqp_get_sockfd function. ->frame_max seems however to not be exposed, so you can't fetch that.

You could probably get direct access to these members if you also include amqp_private.h, be aware that there will be compatibility issues when you do so if you use a different version of the amqp library at runtime than what the header files are created for.

Upvotes: 2

user3099674
user3099674

Reputation: 1

I think that problem is at command below:

state = conn->getConnectionState( );

Are you sure that the getConnectionState() function will return a amqp_connection_state_t type. For sure,you should use state = (amqp_connection_state_t)conn->getConnectionState( );

Upvotes: -1

Related Questions