Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:38:40+00:00 2026-05-27T02:38:40+00:00

I have an ANSI C program comprising two files. The first file contains the

  • 0

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:

  1. When I use GDB to debug, b PI returns (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?

  2. Can I also include the two lines for stdio and stdlib in the myheader.h file?

  3. Can I also include any function prototypes in the myheader.h file? 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:38:41+00:00Added an answer on May 27, 2026 at 2:38 am
    1. It’s normal that a macro definition doesn’t show up in GDB. It’s because GCC replaces each PI with the actual pi value.
    2. Yes. In your case, it doesn’t hurt. If the .h file contains a prototype(they are typically called declarations) that uses a type that are defined in somewhere else, you can simply #include in your header files
    3. Yes. You can declare what ever function prototype you want and it won’t do any harm in terms of the functionality of your program. Compiler won’t even check the existence of the definitions of those functions unless you actually call them from somewhere else.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ANSI C program that dynamically loads a .so file using dlopen()
I have a Ruby script that generates an ANSI file. I want to convert
My program has to read files that use various encodings. They may be ANSI,
I have a program that uses ansi terminal codes to do fancy stuff like
I have some ANSI C code that I developed on my Mac, but when
I have a UNIX application written in ansi C that writes data directly to
I have a old school c program that now and then need to tell
I have program proba2.exe and file text.txt in same folder, when I set command
I have a program which generates its own Wireshark pcap-file (sort of a network
The C standard say: The function called at program startup is named main. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.