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
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
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
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
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
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
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
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
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
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
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
LEARN ABOUT CENTOS
gfs2_tool
gfs2_tool(8) System Manager's Manual gfs2_tool(8)
NAME
gfs2_tool - interface to gfs2 ioctl/sysfs calls
SYNOPSIS
gfs2_tool COMMAND [OPTION]...
DESCRIPTION
gfs2_tool is an interface to a variety of the GFS2 ioctl/sysfs calls. Some of the functions of gfs_tool have been replaced by standard sys-
tem tools such as mount and chattr, so gfs2_tool doesn't have as many options as gfs_tool used to.
COMMANDS
clearflag Flag File1 File2 ...
Clear an attribute flag on a file. This is now obsolete and kept only for backward compatibility, chattr is the preferred way to
clear attribute flags. See setflag for available flags. This option will probably be removed at a future date.
freeze MountPoint
Freeze (quiesce) a GFS2 cluster.
gettune MountPoint
Print out the current values of the tuning parameters in a running filesystem. A better source of similar (more comprehensive)
information is that in the /proc/mounts file. Running the mount command with no arguments will also provide the same information.
This option is considered obsolete and will probably be removed at some future date.
journals MountPoint
Print out information about the journals in a mounted filesystem.
lockdump MountPoint
Print out information about the locks this machine holds for a given filesystem. This information is also available via the debugfs
glock dump file, and accessing that file is the preferred method of obtaining a dump of the glock state.
sb device proto [newvalue]
View (and possibly replace) the name of the locking protocol in the file system superblock. The file system shouldn't be mounted by
any client when you do this.
sb device table [newvalue]
View (and possibly replace) the name of the locking table in the file system superblock. The file system shouldn't be mounted by
any client when you do this.
sb device ondisk [newvalue]
View (and possibly replace) the ondisk format number in the file system superblock. The file system shouldn't be mounted by any
client when you do this. No one should have to use this.
sb device multihost [newvalue]
View (and possibly replace) the multihost format number in the file system superblock. The file system shouldn't be mounted by any
client when you do this. No one should have to use this.
sb device uuid [newvalue]
View (and possibly replace) the uuid in the file system superblock. The file system shouldn't be mounted by any client when you do
this. The new uuid value should be in the standard uuid format. For example: 1AEA8269-15C5-72BD-6D83-8720B17AA4EE
sb device all
Print out the superblock.
setflag Flag File1 File2 ...
Set an attribute flag on a file. The currently supported flags are jdata, immutable, appendonly, noatime, and sync. The chattr
command is the preferred way to set attributes on files. This option will probably be removed at a future date.
The jdata flag causes all the data written to a file to be journaled. If the jdata flag is set for a directory, all files and
directories subsequently created within that directory are also journaled. This behavior replaces the old inherit_jdata flag from
gfs. Same as chattr +j.
The immutable flag marks the file immutable. The behavior is similar to the immutable flag in the ext2/3 filesystems. All write
access is denied. Same as chattr +i.
The appendonly flag causes all data to be written at the end of the file. Same as chattr +a.
The noatime flag disables updates to the file's access time. Same as chattr +A.
The sync flag causes data written to the file to be sync'ed to stable storage immediately. Same as chattr +S.
settune MountPoint parameter newvalue
Set the value of tuning parameter. Use gettune for a listing of tunable parameters. The mount -oremount command is the preferred
way to set the values of tunable parameters. At some future stage, when all parameters can be set via mount, this option will be
removed.
unfreeze MountPoint
Unfreeze a GFS2 cluster.
version
Print out the version of GFS2 that this program goes with.
withdraw MountPoint
Cause GFS2 to abnormally shutdown a given filesystem on this node. This feature is only useful for testing and should not be used
during normal filesystem operation.
gfs2_tool(8)