Author Topic: Console for testing purposes  (Read 5779 times)

Offline vicent

  • Single posting newcomer
  • *
  • Posts: 8
  • Compiling and running
    • VGB's webpage
Console for testing purposes
« on: December 10, 2021, 06:00:49 pm »
Dear all,

Sorry if this question is too naive. Anyway, I hope I can get your help, and I also hope this will be useful to others.

I am used to the 'console' in Rstudio, for instance (also in Scilab, Matlab,...), meaning an interactive command-line interface in which you can execute commands or functions belonging to either system, user-defined or third-party libraries that have been previously included/loaded/defined/declared in the current session.

I find this sort of console very useful, since it allows the programmer to check whether the functions they coded behave as expected or not.

I know that C works differently, since programs need to be compiled before being called/used/recognised.

Anyway, how can I get a sort of 'console' where I can 'play' with the functions I am building or using, either in Code::Blocks or outside it? My OS is Windows 10.

Should I just open a DOS console and use my functions (previously compiled), or do I need to have something else into account?

I look forward to your answers.

---

EDIT:

In case it helps, the functions I am interested in testing are bundled in an 'h' header. After compiling my current project, I have an 'o' file for each of my libraries, but only an 'exe' file for the main routine, as expected.

I understand that I cannot 'play' with my functions without previously compiling them, can I?
« Last Edit: December 10, 2021, 06:22:45 pm by vicent »
vicent

Offline jordi

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Console for testing purposes
« Reply #1 on: December 10, 2021, 10:55:44 pm »
Hi,
Correct. You have to compile you main program and link with the libraries to create the executable.

Seeing Code::Blocks (I am a newbie too), I have known squirrel-lang.  The syntax is similar to C.
http://www.squirrel-lang.org/
It needs more knowledge, you might create your C/C++ libraries and use them with squirrel-lang through bindings.

cling could be an alternative but I don't know if there is binaries for windows
https://github.com/root-project/cling
Regards

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3255
Re: Console for testing purposes
« Reply #2 on: December 11, 2021, 09:16:36 pm »
A "console" like you wish exist, like you noted, only in interpreted languages like python, lua, matlab ecc...
There are some jit compiler for c/c++ (for example https://blog.quarkslab.com/easyjit-just-in-time-compilation-for-c.html, or https://github.com/root-project/cling)
but this is not really related to codeblocks.... If you have some jit compiler you want to test, you can ask and we can look if we can implement something

Offline vicent

  • Single posting newcomer
  • *
  • Posts: 8
  • Compiling and running
    • VGB's webpage
Re: Console for testing purposes
« Reply #3 on: December 14, 2021, 09:56:54 am »
Hi,
Correct. You have to compile you main program and link with the libraries to create the executable.

Seeing Code::Blocks (I am a newbie too), I have known squirrel-lang.  The syntax is similar to C.
http://www.squirrel-lang.org/
It needs more knowledge, you might create your C/C++ libraries and use them with squirrel-lang through bindings.

cling could be an alternative but I don't know if there is binaries for windows
https://github.com/root-project/cling
Regards

Thank you, @jordi, but I chose C over R and Scilab ---which I have already worked with--- because it is faster and as reliable as them. Besides, I need to use the GNU Scientific Library (GSL) in my projects, and I am uncertain about whether this library is available for Squirrel.

BTW, I've programmed in C in the past, but it is now, after having tried Rstudio, that I am missing that console thing.
vicent

Offline vicent

  • Single posting newcomer
  • *
  • Posts: 8
  • Compiling and running
    • VGB's webpage
Re: Console for testing purposes
« Reply #4 on: December 14, 2021, 10:01:55 am »
Hi @BlueHazzard and all,

I was thinking (more) about my question...

Maybe it is just as simple as running a programme in debug mode and setting a breakpoint just after starting the `main` routine. In that very moment, can I access any sort of console in the debug mode, a console in which I can call the functions that have been included in the header and do calculations with them?

I look forward to your answer.
vicent

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3255
Re: Console for testing purposes
« Reply #5 on: December 14, 2021, 11:22:15 am »
Yes, you can use the evaluation of expressions during debugging, and as far as i know it is also possible to make function calls...
You can do this in two ways: start the debugger, open the watches window and type your expresseion in the watches window,
or you start the debugger, switch to the debugger tab in the log window at the bottom. There you can add any gdb command in the Command field at the bottom
for example:
https://stackoverflow.com/questions/1354731/how-to-evaluate-functions-in-gdb

but i do not think that the experience is very pleasant

Offline vicent

  • Single posting newcomer
  • *
  • Posts: 8
  • Compiling and running
    • VGB's webpage
Re: Console for testing purposes
« Reply #6 on: December 17, 2021, 05:58:05 pm »
Yes, you can use the evaluation of expressions during debugging, and as far as i know it is also possible to make function calls...
You can do this in two ways: start the debugger, open the watches window and type your expresseion in the watches window,
or you start the debugger, switch to the debugger tab in the log window at the bottom. There you can add any gdb command in the Command field at the bottom
for example:
https://stackoverflow.com/questions/1354731/how-to-evaluate-functions-in-gdb

but i do not think that the experience is very pleasant

Dear @BlueHazzard. The first solution worked for me, although it is not as 'practical' as a true debugging console.

I am curious about this: how do you test functions you have just programmed for the first time? I mean, how do you perform some callings to these new routines, just to check that they seem to be working OK, before continuing building more code based on them?
vicent

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3255
Re: Console for testing purposes
« Reply #7 on: December 17, 2021, 09:59:57 pm »
For functions i have not written by myself: Read documentation, when possible read the code behind the function (if simple, or shit really hits the fan) and simply use and debug the function.
For functions i have written by myself: Read the code, write tests (so other functions, that test your function automatically) and actually use the function ;)

I never used "interactive" programming languages, beside matlab/octave in university and python at work (and it was not pleasant....)