How to compile/run code script natively?

Obviously I’m not familiar with proper programmer/computer lingo, so apologies if I have made, and will make mistakes naming things here.

Let’s say I type up a code script in a .txt document, on a new computer that has no IDE on it. Is there a way I can compile and run the script by the computer’s own native devices?

Going a step further, would it be possible to solidify the compiled code as a finalized executable that can itself be independently copied and run?

It depends upon the language. For C, this is typically straightforward.

  1. Write code (it does not matter what editor you use)

  2. Compile code with GCC or whatever compiler you have installed

  3. Run code

This article has a nice overview: What is The C Programming Language? A Tutorial for Beginners

1 Like

I just typed “GCC” in my windows search bar and the program yielded is Command Prompt.

Could I use Command Prompt to somehow run the code sheet? If so, by what instructions would I do so?

If you are on Windows, I would use WSL (Windows Subsystem for Linux). It is mentioned in the article I linked:

Not all languages compile. Some languages will require you to install a compiler or tools to use the compiler. Some languages that don’t compile will need runtime environments to be installed. It really just depends. You don’t need an IDE, but you will probably need to use the command line (also called “terminal”). It all just depends on the language and the computer you’re using.

1 Like

Every programming language code we write as a script has a specific file extension, and .txt is no file extension for any programming language. It is the extension for the text file.
If you have stored any programming language code as a.txt then you first need to change the file extension to appropriate script file.
For instance if its contain Python code then the script name must be a.py .
And as far as the compilation or execution of the code goes natively, you first need to install the appropriate compilers or interpreters. Computer can not run any random given instruction it need a translator like compiler and interpreter to read and execute the code script.
Systems like MacOS and Linux comes with preinstall compilers and interpreters for popular programming languages, but if the script is not running on your system, there you need to install the proper compiler.

1 Like

Some basics: There are two types of programming languages - compiling and script languages.
A script language has a program called “interpreter” and that will read and execute your code on the spot. Those are generally easier to learn and use, as the interpreter can do A LOT of work on the fly and it can just run over the code the moment you start it. However this means the interpreter is running in the background and hence slowing down the program.

A compiler language has a program called “compiler” and that will take you code and turn it into an independant executable file. This means you cannot run or change code on the fly, because the ENTIRE CODE has to be compiled before it can be run. Because you don’t execute the code, you execute the file that is produced out of it. So there is no difference inbetween changing a single character or changing thousand lines - the compiler has to compile everything new.
Compilers are harder to write and use as you have to make sure the final file is able to deal with everything you throw at it. There is no program on top working for you, also meaning they are generally a lot faster in execution.

For example, compiler languages need you to specify what datatype variables are. If you say something is an integer, then it can only hold integers. However if you give a float to an integer in an interpreter-language, the interpreter can just change the datatype for you.

Now there are some languages trying both, but I am no expert on them.
Because everything your write is text, the file extension doesn’t really matter, unless you got an IDE with additional features. Ofcourse using an IDE is the preferred way to write code instead of plain text editors.

With that said, without an installed compiler/interpreter, no code you write can be truned into anything. Because it’s just text. However a computer is a machine that has to run code all the time, so there are ways to have code get executed on a native machine. Like, if I write a command in the command-prompt, I obviously want it to interpret the text and do something.

Buuuut - in the end, for more complex tasks you’ll grab an IDE, even if it is lightweight. Simply because of the programming language you use and because even basic features like code-highlighting or automatic indentation.

2 Likes

So you have something specific that you want to do? Because we can kinda give general answers about how certain things might work in practice, but it’s normally easier if there’s some task you have in mind.

3 Likes

I’ve replicated some text from the freecodecamp beginner course video - the initial “Hello World” message that opens by default in code-blocks- and saved in a Notepad file, which I have just now saved as a .c. To introduce myself to the prospect of running a c program from Command Prompt, I just want to start with this.

However, getting Command Prompt to follow into the folder is its own fun project. Each time I type the address to the program, ending in ‘gcc Hello_World.c’, I get the message: “‘G:\000_New_Storage\Media\Documents\Code\C\gcc’ is not recognized as an internal or external command, operable program or batch file.”

I can’t provide any better answers than you would get using Google. This sort of thing is why I recommended using the WSL.