I have an ANSI C program comprising two files. The first file contains the main() function, and the second file contains other functions that the first file calls. Before the main() function definition, I've placed the following code:
#define PI 3.14159265358979323846
but the 2nd file didn't see this variable. The first file sees it fine. Then, I placed this same line in the second file (while keeping it in the first file as above), before the function definitions, but still the second file doesn't see it. Things always compile fine, but when tracing the variable PI in gdb, it shows "No symbol "PI" in current context."
How to make PI a global constant viewable across all files compiled in the application?
EDIT / UPDATE:
Based on the response so far, I've created the following file:
myheader.h
#ifndef my_header_stuff
#define my_header_stuff
#define PI 3.1415926535897932384626433832795
#endif
and in the two files I want to see this constant PI, I've included this file as follows:
file1.c
#include <stdio.h>
#include <stdlib.h>
#include "myheader.h"
int main(void) {
etc...
}
and file2.c
#include <stdio.h>
#include <stdlib.h>
#include "myheader.h"
double interesting_function(void) {
etc...
}
Questions:
When I use GDB to debug,
b PIreturns (in both files, same result) "No symbol "PI" in current context". However, the math depending on PI is computed correctly. Is there a way to view PI in gdb?Can I also include the two lines for stdio and stdlib in the
myheader.hfile?Can I also include any function prototypes in the
myheader.hfile? If I do, and then let's say I create a file3.c that doesn't require any of these prototypes because it doesn't use those functions, is any harm done?