Your question was whether you can test a given C file on a CPU architecture different from the machine you're working on. For example, you may have a Windows machine with an Intel processor, but want to try the program on an ARM platform.
This can of course be done.
The thing to note is that C code never runs directly on a CPU; it first has to be translated (compiled) into machine code, as different platforms require different machine code to do the same thing. This is what a compiler does.
You can tell a compiler to compile your code into a different target platform. This is called cross-compiling. This blog post, for example, describes how to cross-compile a Hello World program to ARM using the arm-linux-gnueabi-gcc
compiler (which you can get under Ubuntu from apt install gcc-arm-linux-gnueabi
).
I should add that these sort of things are somewhat easier under Linux hosts than Windows, but maybe that's a personal bias.
Once you have cross-compiled your program, you may want to test it on the target platform. For this, you will need a CPU emulator, of course, but that emulator alone will not be enough, as you need an operating system on top of it,* which can load the respective compiled C program and execute it as a process. The ARM Lab VM does that for ARM. It's a virtual machine that emulates an ARM platform on any host platform.
* Unless that program itself is “bare-metal”, which means that it runs without an intermediate operating system.
Maybe you can try with a container? – Babblo – 2018-11-12T13:42:49.137
Container like a Docker container? can you explain it? – Tailor – 2018-11-12T13:46:33.310
2What do you mean by "run a C-File"? Do you mean to run a C program compiled to run on different hardware which you emulate? Or compile a C program using a compiler for different hardware running in an emulator? Or are you looking for a C interpreter? Or what? – AFH – 2018-11-12T13:47:08.273
Agree with @AFH – this question does not make much sense. Could you please explain the context of your problem? – slhck – 2018-11-12T13:52:02.627
I had the idea of emulating a arm cpu to run different programs. To begin with, I wanted emulate the cpu and run for example a simple hello world written in C. Sry for my bad explanation – Tailor – 2018-11-12T13:55:07.863
1Given this, the answer may not make a lot of sense. Do you want to test how or whether a program you've developed can be compiled for and run on an ARM platform? (Please respond to people with @username, otherwise they will not get a notification.) – slhck – 2018-11-12T14:07:31.897
Yes, thats what I am trying to do – Tailor – 2018-11-12T14:10:27.970
1The simple answer is that you would have to compile (and link) a C program before you could execute it with an ARM emulator (or any CPU for that matter). You could cross-compile your C program on the host (the most sensible choice) with a cross toolchain, or natively compile it with the ARM emulator if it has an OS and toolchain installed. – sawdust – 2018-11-12T21:18:53.993