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 8259179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:47:56+00:00 2026-06-08T02:47:56+00:00

If i have a C source file and i want to locate a specific

  • 0

If i have a C source file and i want to locate a specific local variable within a function and make it global – so another tool is able to process the C file (a tool i didn’t write) what would be the easiest way to do this? I was thinking of using regex, but even that posses it’s own problems. It’s kind of like writing a mini C parser in Java.. a lot of work :S

Are there any libraries that can help make this easier?

For example, say i want to make the variable “i” into a global variable. The user will specify the function name and the variable name (but not the type the variable is – ie. “int”).

I can use regex to find the function – sure. But from there i really don’t know what the best approach would be?… Will CDT plugin help?

Example:

 /* 
  * add.c
  * a simple C program
  *
  */

#include <stdio.h>
#define LAST 10

int main()
{
    int i = 0;
    int sum = 0;

    for ( i = 1; i <= LAST; i++ ) {
      sum += i;
    } /*-for-*/
    printf("sum = %d\n", sum);

    return 0;
}

converted to:

 /* 
  * add.c
  * a simple C program
  *
  */

#include <stdio.h>
#define LAST 10

int i = 0;

int main()
{

    int sum = 0;

    for ( i = 1; i <= LAST; i++ ) {
      sum += i;
    } /*-for-*/
    printf("sum = %d\n", sum);

    return 0;
}
  • 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-06-08T02:47:58+00:00Added an answer on June 8, 2026 at 2:47 am

    The first thing I would demand is a complete specification of exactly when this is required and why, and how to identify when it is safe to do so without adversely affecting the program semantics. This is a really bad idea. Clearly those who gave you the assignment have no idea of either the implementation complexity, which is immense, or the adverse semantic effects. I am guessing that they will therefore be unable to come up with an adequate specification either, which will ultimately let you out.

    I would also draw their attention to this discussion, especially Ira Baxter’s comments. I used to build compilers for a living. It is not a task to learn, or ask about, on a forum.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem: I want to generate a new source code file from
Here is more specific explanation of what I want to make clear: I have
I want to have a source file which can compile with javac / ecj
I have many source/text file, say file.cpp or file.txt . Now, I want to
i have a source file i want to load through sqlload in my Oracle
I have a source file. When I compile the code, I want the executable
I have a C source file having comments in // (C++) style. I want
I have a source file, openpage.pl, where I call use_module/1 to import SWI-Prolog's http_open/3:
I have a source file where 2 features have been added. In order to
Suppose I have a source file open and I launch a shell. I can

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.