Sponsored Content
Full Discussion: C header file and extern
Top Forums Programming C header file and extern Post 302851859 by tornow on Tuesday 10th of September 2013 12:11:34 AM
Old 09-10-2013
Thanks. Your explanation and example makes it more clear (also thanks for pointing out it may not be best praxis, but for now i just try to understand the general idea).

I think you say that: header files are (or can be ) used _instead of declaring the variable foo as extern in File2 and File3. foo is defined in File1 (and storage is set aside for it). File1 includes myheader.h too, and if foo is declared (File2 and File3) or defined (File1) is decided by the #ifndef Mainfile and #define Mainfile in File1.

I read in §The C Programming langauge"; (As "C A modern approach" was not clear on the subject) and in chapter 1 "External variables and scope" (page 33 for me) it says the following (or that is what i understand):
- a definition creates a variable and sets aside storage
- a declaration only announces the nature of a variable
- extern says that the definition is elsewhere and only declares
- header files include declarations, not definitions
Is both correct (What i understood of your post and what i understood of the book)?

I think i am getting closer to understand it. Let me rethink and read again.Really thanks.
 

10 More Discussions You Might Find Interesting

1. Programming

extern for functions

Hi, Please let me know if the extern keyword is necessary for using functions which is defined and declared in another file and and used in a different file where both these files are linked together. thanks (8 Replies)
Discussion started by: naan
8 Replies

2. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies

3. Programming

Extern variable.

file1.c int a1; int main() { a1 = 2; printf("\na1 = %d\n", a1); next(); printf("\na1 = %d\n", a1); next1(); printf("\na1 = %d\n", a1); } file2.c #include <stdio.h> int b1 = 0; void next(void) (1 Reply)
Discussion started by: Tanvirk
1 Replies

4. Linux

Problem mounting extern hd (fedora 9)

Hi there, I'm having a bit of a strange problem which I would appreciate some help with. The Problem: I have two external hard drives, but I'm borrowing one off my parents to copy data too (one of mine, which is identical to theirs - WD MyBook 300g - is on its way out). Fedora 9 recognizes... (3 Replies)
Discussion started by: lasthidingplace
3 Replies

5. UNIX for Dummies Questions & Answers

fetchmail and forward to an extern address

Hi, I'm searching for an solution for the following problem. I want fetch some mails via pop3 from a@a.com with fetchmail. That works perfectly. Now any incoming mail should forwarded to b@b.com via smtp obv. But I don't know how to configure that. All online tutorials describe forwarding to... (0 Replies)
Discussion started by: mcW
0 Replies

6. Programming

segmentation fault for extern

Why this is happening when both of them compiled together and run? I am getting segmentation fault SIGSEGV. File1.c: int arr; File2.c: extern int *arr; int main() { arr = 100; } (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Shell Programming and Scripting

Comparing one file header with another file header

Hi Experts, In our project we have requirement where in we have to compare header of one file with header in the parameter file. There are 20 files which we ftp from one site. All this files have different header. We are comapring this file with our parameter file(which is having the header... (2 Replies)
Discussion started by: Amey Joshi
2 Replies

8. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

9. Programming

Extern keyward on function in C

I saw a header (.h) file with mixture of "regular" function declarations and other extern function declarations. As I was told all function declarations are implicitly external and the extern on functions declarations is superfluous. Here my focus is on function declaration, not variable yet. int... (2 Replies)
Discussion started by: yifangt
2 Replies

10. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies
Tt/tttk.h(file formats) 												   Tt/tttk.h(file formats)

NAME
Tt/tttk.h -- ToolTalk definitions SYNOPSIS
#include <Tt/tttk.h> DESCRIPTION
The Tt/tttk.h header defines the following enumeration data type, with at least the following members: Tttk_op TTDT_CREATED, TTDT_DELETED, TTDT_DO_COMMAND, TTDT_GET_ENVIRONMENT, TTDT_GET_GEOMETRY, TTDT_GET_ICONIFIED, TTDT_GET_LOCALE, TTDT_GET_MAPPED, TTDT_GET_MODIFIED, TTDT_GET_SITUATION, TTDT_GET_STATUS, TTDT_GET_SYSINFO, TTDT_GET_XINFO, TTDT_LOWER, TTDT_MODI- FIED, TTDT_MOVED, TTDT_OP_LAST, TTDT_OP_NONE, TTDT_PAUSE, TTDT_QUIT, TTDT_RAISE, TTDT_RESUME, TTDT_REVERT, TTDT_REVERTED, TTDT_SAVE, TTDT_SAVED, TTDT_SET_ENVIRONMENT, TTDT_SET_GEOMETRY, TTDT_SET_ICONIFIED, TTDT_SET_LOCALE, TTDT_SET_MAPPED, TTDT_SET_SITUATION, TTDT_SET_XINFO, TTDT_SIGNAL, TTDT_STARTED, TTDT_STATUS, TTDT_STOPPED, TTME_ABSTRACT, TTME_COMPOSE, TTME_DEPOSIT, TTME_DISPLAY, TTME_EDIT, TTME_INSTANTIATE, TTME_INTERPRET, TTME_MAIL, TTME_MAIL_COMPOSE, TTME_MAIL_EDIT, TTME_PRINT, TTME_TRANSLATE The header declares the following global string constants for some standard vtypes: extern const char *Tttk_boolean: extern const char *Tttk_file: extern const char *Tttk_height: extern const char *Tttk_integer: extern const char *Tttk_message_id: extern const char *Tttk_string: extern const char *Tttk_title: extern const char *Tttk_width: extern const char *Tttk_xoffset: extern const char *Tttk_yoffset: The header declares the following as functions: int ttdt_Get_Modified(Tt_message context, const char *pathname, Tt_scope the_scope, XtAppContext app2run, int ms_timeout); Tt_status ttdt_Revert(Tt_message context, const char *pathname, Tt_scope the_scope, XtAppContext app2run, int ms_timeout); Tt_status ttdt_Save(Tt_message context, const char *pathname, Tt_scope the_scope, XtAppContext app2run, int ms_timeout); Tt_status ttdt_close(const char *procid, const char *new_procid, int sendStopped); Tt_status ttdt_file_event(Tt_message context, Tttk_op event, Tt_pattern *patterns, int send); Tt_pattern *ttdt_file_join(const char *pathname, Tt_scope the_scope, int join, Ttdt_file_cb cb, void *clientdata); Tt_message ttdt_file_notice(Tt_message context, Tttk_op op, Tt_scope scope, const char *pathname, int send_and_destroy); Tt_status ttdt_file_quit(Tt_pattern *patterns, int quit); Tt_message ttdt_file_request(Tt_message context, Tttk_op op, Tt_scope scope, const char *pathname, Ttdt_file_cb cb, void *client_data, int send_and_destroy); Tt_pattern *ttdt_message_accept(Tt_message contract, Ttdt_contract_cb cb, Widget shell, void *clientdata, int accept, int sendStatus); char *ttdt_open(int *ttfd, const char *toolname, const char *vendor, const char *version, int sendStarted); Tt_status ttdt_sender_imprint_on(const char *handler, Tt_message contract, char **display, int *width, int *height, int *xoffset, int *yoffset, XtAppContext app2run, int ms_timeout); Tt_pattern *ttdt_session_join(const char *sessid, Ttdt_contract_cb cb, Widget shell, void *clientdata, int join); Tt_status ttdt_session_quit(const char *sessid, Tt_pattern *sess_pats, int quit); Tt_pattern *ttdt_subcontract_manage(Tt_message subcontract, Ttdt_contract_cb cb, Widget shell, void *clientdata); Tt_status ttmedia_Deposit(Tt_message load_contract, const char *buffer_id, const char *media_type, const unsigned char *new_contents, int new_len, const char *pathname, XtAppContext app2run, int ms_timeout); Tt_message ttmedia_load(Tt_message context, Ttmedia_load_msg_cb cb, void *clientdata, Tttk_op op, const char *media_type, const unsigned char *contents, int len, const char *file, const char *docname, int send); Tt_message ttmedia_load_reply(Tt_message contract, const unsigned char *new_contents, int new_len, int reply_and_destroy); Tt_status ttmedia_ptype_declare(const char *ptype, int base_opnum, Ttmedia_load_pat_cb cb, void *clientdata, int declare); void tttk_Xt_input_handler(XtPointer procid, int *source, XtInputId *id); Tt_status tttk_block_while(XtAppContext app2run, const int *blocked, int ms_timeout); Tt_status tttk_message_abandon(Tt_message msg); Tt_message tttk_message_create(Tt_message context, Tt_class the_class, Tt_scope the_scope, const char *handler, const char *op, Tt_message_callback callback); Tt_status tttk_message_destroy(Tt_message msg); Tt_status tttk_message_fail(Tt_message msg, Tt_status status, const char *status_string, int destroy); Tt_status tttk_message_reject(Tt_message msg, Tt_status status, const char *status_string, int destroy); char *tttk_op_string(Tttk_op opcode); Tttk_op tttk_string_op(const char *opstring); Tt/tttk.h(file formats)
All times are GMT -4. The time now is 04:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy