4 Replies - 401 Views - Last Post: 04 December 2012 - 10:59 AM Rate Topic: -----

#1 guru2086  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-December 12

header file functions in c

Posted 03 December 2012 - 01:15 PM

I am new to C/C++ and i am not able to understand how the header files work in C i have a set of header files being used in various functions in my project and they have functions that are being called in my programs. When i go to see functions code in the header file I could only see the function defination but no body Header file contains only the varriable /Structure and function definations. where is the code that is getting executed.

here is one sample header file.


#ifndef _SAMPLE_UTILS_H_
#define _SAMPLE_UTILS_H_ 1

#ifdef  __cplusplus
extern "C" {
#endif


int print_key_info (R_KM_KEY *key);
int print_security_obj_info(R_KM_KEY *key);
int print_symmetric_key_info(R_KM_KEY *key);

void print_buffer (char *label, unsigned char *buf, unsigned int bufLen,
    char *indent);

int write_data_to_file (char *filename, unsigned char *input, unsigned long
    inputLen);

int read_data_from_file (char *filename, unsigned char **pInput,
    unsigned long *pInputLen);

int hex_string_to_binary (char *hex_str, unsigned char *bin_buf,
    unsigned int *bin_len);

int fips_mode_string_to_int(char *mode_buffer, int *format);

int crypto_format_string_to_int(char *mode_buffer, int *format);

int get_substring_by_index(char *str, const char *delimiters, int index,
    char **substr, unsigned int *substr_len);

int extract_key_alias_from_string(char *key_alias, int cnt,
    unsigned char *alias_data, unsigned int alias_max_len,
     unsigned int *alias_data_len);

int extract_key_attribute_name_from_string(char *key_attribute, int cnt,
    char *attribute, unsigned int attr_max_len);

int extract_key_attribute_from_string(char *key_attribute, int cnt,
    char *attr_name, unsigned int attr_name_max_len, int *attr_type,
    int *is_private, unsigned char *attr_value, unsigned int attr_value_max_len,
    unsigned int  *attr_value_len);

int string_to_key_state_data(char *key_state, int *state, int *sub_state,
    char *state_desc, unsigned int desc_max_len);

/* This has been lifted from RSA samples.*/
typedef struct km_util_config
{
    char *init_file;
    char *svc_file;
    char *credential_password;
    char *cache_password;
    char *key_class;
    char *key_alias;
    char *key_alias_add;
    char *key_alias_delete;
    char *key_attribute;
    char *key_attribute_add;
    char *key_attribute_delete;
    char *key_attribute_update;
    char *key_state;
    char *not_before;
    char *key_infile;
    char *key_digest_infile;
    char *key_file;
    int key_format;
    char *uuid;
    char *key_id;
    char *in_file;
    char *out_file;
    char *iv_file;
    int fips_mode;
    int fips_mode_set;
    int out_data_format;
    int out_data_format_set;
    char **header_name_string;
    unsigned char **header_value_string;
    int headers_added;
    char *out_iv_file;
    char *out_key_id_file;
    char *in_mac_file;
    char *unknown;
    int threads;
    int iterations;

} KM_UTIL_CONFIG;

int is_valid_option(char *valid_option_list[], char *option);

const char *get_key_source_desc (int source);

int parse_param(int argc, char *argv[], char *valid_option_list[],
    KM_UTIL_CONFIG *km_util_config);

int initialise_kmc(R_KM_CTX **km_ctx, R_KM_KEY_CTX **km_key_ctx,
    KM_UTIL_CONFIG *km_util_config);

int shutdown_kmc(R_KM_CTX *km_ctx, R_KM_KEY_CTX *km_key_ctx);

int concat_buffers(unsigned char *src1, unsigned int src1_len,
    unsigned char *src2, unsigned int src2_len, unsigned char **dest,
    unsigned int *dest_len);

#ifdef  __cplusplus
}
#endif

#endif


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 03 December 2012 - 02:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: header file functions in c

#2 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: header file functions in c

Posted 03 December 2012 - 07:39 PM

A header file just contains declarations. Those can be function declarations, #define macros, constants etc...

The implementation of it are in the library file, having the extension of .lib, .dll or .a...

For the user-defined headers, we normally put all the declarations in the header file, say: myHeader.h, and the implementations in myHeader.cpp...

Here is more about headers...
Was This Post Helpful? 1
  • +
  • -

#3 guru2086  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-December 12

Re: header file functions in c

Posted 04 December 2012 - 10:26 AM

View PostAKMafia001, on 03 December 2012 - 07:39 PM, said:

A header file just contains declarations. Those can be function declarations, #define macros, constants etc...

The implementation of it are in the library file, having the extension of .lib, .dll or .a...

For the user-defined headers, we normally put all the declarations in the header file, say: myHeader.h, and the implementations in myHeader.cpp...

Here is more about headers...

So in case we have provided a signature of a function in header file it should be supported by the library.So my next question is where are libraries supposed to be, if they are default libraries how would they provide an implementation for user defined function.<br> it may sound stupid but the reason i am asking is i dont see any additional libraries in my code the only flow i am able to follow ends in the header files.</br> <b>thanks</b>
Was This Post Helpful? 0
  • +
  • -

#4 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: header file functions in c

Posted 04 December 2012 - 10:46 AM

It doesn't sound stupid at all...

As I said, the implementation for built-in functions and stuff are in the library files having .lib, .dll or .a extensions. They are contained in your compiler directory, normally in lib folder..

For your header files, the simplest way is to put the implementations in a .cpp file having a name same as the header file...

Then if you want to use something from your header, say, a function, you can simply add the header file with double quotes (" ") in the file where the functions will be used... e.g. #include "myHeader.h" we don't need to specify the .cpp file which contains the implementaton...

When we use the double quotes (" "), it tells the compiler to look for the header in the project directory instead of the compiler's directory...

PS: You can read the link I provided in the earlier post...
Hope this Helps!

This post has been edited by AKMafia001: 04 December 2012 - 10:47 AM

Was This Post Helpful? 0
  • +
  • -

#5 guru2086  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-December 12

Re: header file functions in c

Posted 04 December 2012 - 10:59 AM

View PostAKMafia001, on 04 December 2012 - 10:46 AM, said:

It doesn't sound stupid at all...

As I said, the implementation for built-in functions and stuff are in the library files having .lib, .dll or .a extensions. They are contained in your compiler directory, normally in lib folder..

For your header files, the simplest way is to put the implementations in a .cpp file having a name same as the header file...

Then if you want to use something from your header, say, a function, you can simply add the header file with double quotes (" ") in the file where the functions will be used... e.g. #include "myHeader.h" we don't need to specify the .cpp file which contains the implementaton...

When we use the double quotes (" "), it tells the compiler to look for the header in the project directory instead of the compiler's directory...

PS: You can read the link I provided in the earlier post...
Hope this Helps!



Thanks.. It helped. I was able to find the source for header file it was on the server it self in an object file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1