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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:11:04+00:00 2026-05-18T09:11:04+00:00

Sorry if the question is worded wrong – I don’t know the right word

  • 0

Sorry if the question is worded wrong – I don’t know the right word for what I’m asking for! 🙂

Say, you have some simple C program like:

#include <stdio.h>

int main()
{
   int a=2; 
   printf("Hello World %d\n", a);
   return 0;
} 

Typically, this would have to be saved in a file (say, hello.c); then we run gcc on the source file and obtain executable file – and if we compiled in debug information, then we can use gdb on the executable, to step through lines of code, and inspect variables.

What I would like to have, is basically some sort of a “C” shell – similar to the Python shell; in the sense that I can have a sequence of Python commands in a file (a script) – or I can just paste the same commands in the shell, and they will execute the same. In respect to the simple program above, this is what I’d like to be able to do (where C> represents the imagined prompt):

C> #include <stdio.h>
(stdio.h included)
C> int a=2;
C> printf("Hello World %d\n", a);
Hello World 2

C> 

In other words, I’d like to be able to execute individual C commands interactively (I’m guessing this would represent on-the-fly compilation of sorts?). Initially I was misled by the name of the C shell (csh) – but I don’t think it will be able to execute C commands on the fly.

So, first and foremost, I’d like to know if it is possible somehow to persuade, say, gdb to perform in this manner? If not, is there anything else that would allow me to do something similar (some special shell, maybe)?

As for the context – I have some code where I have problems troubleshooting pointers between structs and such; here the way gdb can printout structs works very well – however, to isolate the problem, I have to make new source files, paste in data, compile and debug all over again. In this case, I’d much rather have the possibility to paste several structs (and their initialization commands) in some sort of a shell – and then, inspect using printf (or even better, something akin to gdb‘s print) typed directly on the shell.

Just for the record – I’m not really persuaded something like this really exists; but I thought I’d ask anyways 🙂

Thanks in advance for any answers,
Cheers!
 
 

EDIT: I was a bit busy, so haven’t had time to review all answers yet for accept (sorry 🙂 ); just wanted to add a little comment re:”interpreted vs. machine code“; or as mentioned by @doron:

The problem with running C /C++ source interactively is that
the compiler is not able to perform line by line interpretation of the code.

I am fully aware of this – but let’s imagine a command line application (could even be an interpreted one), that gives you a prompt with a command line interface. At start, let’s assume this application generates this simple “text file” in memory:

@@HEADER@@

int main()
{
    @@MAIN@@

    return 0;
} 

Then, the application simply waits for a text to be entered at the prompt, and ENTER to be pressed; and upon a new line:

  • The application checks:
    • if the line starts with #define or #include, then it is added below the @@HEADER@@ – but above the int main() line – in the temp file
    • anything else, goes below @@MAIN@@ line – but above return 0; line – in the temp file
  • the temp file is stripped of @@HEADER@@ and @@MAIN@@ lines, and saved to disk as temp.c
  • gcc is called to compile temp.c and generate temp.out executable
    • if fail, notify user, exit
  • gdb is called to run the temp.out executable, with a breakpoint set at the return 0; line
    • if fail, notify user, exit
  • execution is returned to the prompt; the next commands the user enters, are in fact passed to gdb (so the user can use commands like p variable to inspect) – until the user presses, say, Ctrl+1 to exit gdb
  • Ctrl+1 – gdb exits, control is returned to our application – which waits for the next code line all over again.. etc
    • (subsequent code line entries are kept in the temp file – placed below the last entry from the same category)

Obviously, I wouldn’t expect to be able to paste the entire linux kernel code into an application like this, and expect it to work 🙂 However, I would expect to be able to paste in a couple of structs, and to inspect the results of statements like, say:

char dat = (char) (*(int16_t*)(my->structure->pdata) >> 32 & 0xFF) ^ 0x88; 

… so I’m sure in what is the proper syntax to use (which is usually what I mess up with) – without the overhead of rebuilding and debugging the entire software, just to figure out whether I should have moved a right parenthesis before or after the asterisk sign (in the cases when such an action doesn’t raise a compilation error, of course).

Now, I’m not sure of the entire scope of problems that can arise from a simplistic application architecture as above. But, it’s an example, that simply points that something like a “C shell” (for relatively simple sessions/programs) would be conceptually doable, by also using gcc and gdb – without any serious clashes with the, otherwise, strict distinction between ‘machine code’ and ‘interpreted’ languages.

  • 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-18T09:11:05+00:00Added an answer on May 18, 2026 at 9:11 am

    @buddhabrot and @pmg – thank you for your answers!

    For the benefit of n00bery, here is a summary of the answers (as I couldn’t immediately grasp what is going on): what I needed (in OP) is handled by what is called a “C Interpreter” (not a ‘C shell‘), of which the following were suggested:

    • CINT | ROOT – Ubuntu: install as sudo apt-get install root-system-bin (5.18.00-2.3ubuntu4 + 115MB of additional disk space)
    • c-repl (c-repl README)- Ubuntu: install as sudo apt-get install c-repl (c-repl_0.0.20071223-1_i386.deb + 106kB of additional disk space)
    • Ch standard edition – standard edition is freeware for windows/Unix
       
       

    For c-repl – there is a quick tutorial on c-repl homepage as an example session; but here is how the same commands behave on my Ubuntu Lucid system, with the repository version (edit: see Where can I find c-repl documentation? for a better example):

    $ c-repl 
    > int x = 3
    > ++x
    > .p x
    unknown command: p
    > printf("%d %p\n", x, &x)
    4 0xbbd014
    > .t fprintf
    repl is ok
    > #include <unistd.h>
    <stdin>:1:22: warning: extra tokens at end of #include directive
    > getp
    p getp
    No symbol "getp" in current context.
    > printf("%d\n", getpid())
    10284
    > [Ctrl+C]
    /usr/bin/c-repl:185:in `readline': Interrupt
        from /usr/bin/c-repl:185:in `input_loop'
        from /usr/bin/c-repl:184:in `loop'
        from /usr/bin/c-repl:184:in `input_loop'
        from /usr/bin/c-repl:203
    

    Apparently, it would be best to build c-repl from latest source.
     
     

    For cint it was a bit difficult to find something relateed to it directly (the webpage refers to ROOT Tutorials instead), but then I found “Le Huy: Using CINT – C/C++ Interpreter – Basic Commands“; and here is an example session from my system:

    (Note: if cint is not available on your distribution’s package root-system-bin, try root instead.)

    $ cint
    
    cint : C/C++ interpreter  (mailing list 'cint@root.cern.ch')
       Copyright(c) : 1995~2005 Masaharu Goto (gotom@hanno.jp)
       revision     : 5.16.29, Jan 08, 2008 by M.Goto
    
    No main() function found in given source file. Interactive interface started.
    '?':help, '.q':quit, 'statement','{statements;}' or '.p [expr]' to evaluate
    
    cint> L iostream
    Error: Symbol Liostream is not defined in current scope  (tmpfile):1:
    *** Interpreter error recovered ***
    cint> {#include <iostream>}
    cint> files
    Error: Symbol files is not defined in current scope  (tmpfile):1:
    *** Interpreter error recovered ***
    cint> {int x=3;}
    cint> {++x}
    Syntax Error: ++x Maybe missing ';' (tmpfile):2:
    *** Interpreter error recovered ***
    cint> {++x;}
    (int)4
    cint> .p x
    (int)4
    cint> printf("%d %p\n", x, &x)
    4 0x8d57720
    (const int)12
    cint> printf("%d\n", getpid())
    Error: Function getpid() is not defined in current scope  (tmpfile):1:
    *** Interpreter error recovered ***
    cint> {#include <unistd.h>}
    cint> printf("%d\n", getpid())
    10535
    (const int)6
    cint> .q
      Bye... (try 'qqq' if still running)
    

    In any case, that is exactly what I needed: ability to load headers, add variables, and inspect the memory they will take! Thanks again, everyone – Cheers!

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

Sidebar

Related Questions

Sorry for the basic question - I'm a .NET developer and don't have much
Sorry for the simple question but I feel like there's a smarter way to
Sorry for the poorly-worded question. I was hoping to get everyone's ideas on the
Sorry if the question is confused, as I'm confused myself. I'm working around these
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry for the long question title. I guess I'm on to a loser on
Sorry for the slightly noobish question, as I am writing my first rails app.
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry if this sounds like a really stupid question, but I need to make
Sorry in advance for the long question. What I'm really interested in is a

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.