Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
Accepted Solution

How to use extended/external .c and .h class?

Purpose: Make main.c become smaller.

 

Problem: When the .c file is created, eror shows "implicit declaration of function 'show_dialog_message' [-Wimplicit-function-declaration]" on show_dialog_message

 

Question: How to use extended/external .c and .h class? or Something wrong in the following coding??

 

Mini code: All the required classes are included.

 

The main.c

 

#include "helloworld.c"

if (EXIT_FAILURE == resize(event)) {
   shutdown = true;
}

 

helloworld.c :

 

int resize(bps_event_t *event) {
    if (event) {
    snprintf(msg, MSG_SIZE, "Hello World!!");
    show_dialog_message(msg);
}
return EXIT_SUCCESS;
}

 

helloworld.h

 

int resize(bps_event_t *event);

 

 

Thank your attention,

 

 

 

-Fight with BB10
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to use extended/external .c and .h class?

Hi,

 

In main.c include helloworld.h, not .c

 

.c files are compiled independently.

.h files forward-declare everything implemented in .c files.

 

So when referencing functions implemented in other .c files, include .h file to forward-declare variables and functions.

 

It will work in this case, but generally it's better to guard from multiple inclusion in .h file by using preprocessor commands:

 

helloworld.h

#ifndef HELLOWORLD_H
#define HELLOWORLD_H

int resize(bps_event_t *event);

#endif // HELLOWORLD_H

 


Andrey Fidrya, @zmeyc on twitter
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: How to use extended/external .c and .h class?

That's the key. Thank you to debug my code.

 

love C than Java now.

 

-Fight with BB10