I'm currently developing a gui application in turbo c++ (mandatory) for a project using C language, and i need to invoke turbo c++'s compiler(gcc), my question is HOW DO I CALL IT? i can't find any sources in the internet regarding this.
here's a snippet of my code
int program(){
int opt=-1,j;
char menu[4][20]={"Open File","Compile", "Run","Quit"};
close=1;
dropmenu(menu,10,33,131,105,opt);
do{
showmouse();
getmousepos(&buttonm,&xm,&ym);
if(xm>=10+10&&xm<=131-10&&ym>=33+8&&ym<=105-8&&buttonm==1){
for(j=0;j<(105-33-8)/14;j++)
if((ym-33-8)/14==j){
opt=j;
break;
}
dropmenu(menu,10,33,131,105,opt);
switch(opt){
case 0: openFile(); break;
case 1: compile(); break;
case 2: run(); break;
case 3: delay(100);cleardevice();closegraph();exit(0);
}
}else if(xm>=10&&xm<=34&&ym>=18&&ym<=32&&buttonm==1){
dropmenu(menu,10,33,131,105,opt);
continue;
}else if(buttonm==1){
break;
}
}while(close);
return 0;
}
void openFile() {
}
void compile() {
//i would like to put that invoking here
}
void run() {
}
Firstly gcc is not equivalent to turbo-c. turbo uses tc for compiling the codes. You can probably find that from the documentations of turbo c. To compile a file you can use system function. This function helps to execute command on the turbo c shell. I am not sure gcc would be accessible from the turbo shell. Since turbo elevates(mount) the directories giving it restricted permissions only. Also if you want to use the system it would be like following:
system("tc source.c -o destination");
or
system("gcc source.c -o destination");
remember the above code also shows error if any in the text mode only therefore you might want to redirect them to some file. You can find out about redirecting of output of command line from google. There are many resources about it.
Related
I would like to use a library written in D for a C program compilable with MinGW GCC, for Windows. Here are the codes:
dll.d
extern (C) int dsquare(int n) nothrow
{
return n * n;
}
main.c
#include <stdio.h>
int main()
{
int res = dsquare(6); // Expect '36'
printf("res = %d\n", res);
return 0;
}
There is a tutorial on D's site, but it seems to target only Linux. Indeed, no explanation is given for creating such a dynamic D library for Windows and MinGW users.
D's documentation also says that the -shared option should generate a DLL version of the D code, but in my case, it generates an executable, I don't know why.
Also, anything that seems to generate files to be linked targets MVSC formats and nothing seems to be suitable for MinGW GCC compilers.
So, how can I generate a "GCC-friend" DLL with D, so that I can link it to my C program without having to use another compiler, such as GDC or LDC, via gcc main.c -o main -ldll -L. (I guess)?
I attached link with short explanation. Link D onto C is not so straightforward as C to D. Check D.org page here:
https://dlang.org/spec/betterc.html
I am making a small console game and want to allow instant input and output for the player so that they don't have to hit enter after each move. I understand there are already a few solutions that can be found online, most prominently ncurses (I'm on linux), but I have not been able to get anything to work. When I input the code below, I get the message:
main.cpp:(.text+0x39c): undefined reference to `initscr'
main.cpp:(.text+0x3a3): undefined reference to `stdscr'
main.cpp:(.text+0x3ac): undefined reference to `wgetch'
main.cpp:(.text+0x3b4): undefined reference to `endwin'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I understand skipping the input buffer is not standard in C, but any ways around this would be greatly appreciated. I can make the code work by just using key = getchar(); but as aforementioned, I want to skip the necessary enter key.
void move(int key){
initscr();
key = getch();
switch(key){
case 'w': if (playery > 1){y--;}
break;
case 's': if (playery < height - 1){y++;}
break;
case 'a': if(playerx > 1){x--;}
break;
case 'd': if(playerx < width - 1){x++;}
break;
default: grid[x][y] = 'x';
break;
}
endwin();
}
You need to link with ncurses to make it work. When you include curses.h or ncurses.h, it includes just the definitions. The actual code is separated, so you have to tell your compiler to add the code to your program.
Compiling with clang
Use this when compiling C++:
clang++ main.cpp -lncurses
Use this when compiling C:
clang main.c -lncurses
Never use clang with C++ or clang++ with C. It creates a huge mess.
Compiling with GNU/gcc
Use this when compiling C++:
g++ main.cpp -lncurses
Use this when compiling C:
gcc main.c -lncurses
Again, do not interchange those.
You say you use C, but you have main.cpp, which implies you are using C++. Rename your file to main.c or edit your question.
As noted in comments, ncurses already has a function named move. You should rename your function.
The newer versions of gcc offer the Wimplicit-fallthrough, which is great to have for most switch statements. However, I have one switch statement where I want to allow fall throughs from all case-statements.
Is there a way to do an explicit fall through? I'd prefer to avoid having to compile with Wno-implicit-fallthrough for this file.
EDIT: I'm looking for a way to make the fall through explicit (if it's possible), not to turn off the warning via a compiler switch or pragma.
Use __attribute__ ((fallthrough))
switch (condition) {
case 1:
printf("1 ");
__attribute__ ((fallthrough));
case 2:
printf("2 ");
__attribute__ ((fallthrough));
case 3:
printf("3\n");
break;
}
GCC fallghrough magic comments
You should not use this if you can help it, it is insane, but good to know about:
int main(int argc, char **argv) {
(void)argv;
switch (argc) {
case 0:
argc = 1;
// fall through
case 1:
argc = 2;
};
}
prevents the warning on GCC 7.4.0 with:
gcc -Wall -Wextra main.c
man gcc describes how different comments may or not be recognized depending on the value of:
-Wimplicit-fallthrough=n
C++17 [[fallthrough]] attribute
C++17 got a standardized syntax for this: GCC 7, -Wimplicit-fallthrough warnings, and portable way to clear them?
You should be able to use GCC diagnostic pragmas to disable that particular warning for your source file or some portion of a source file. Try putting this at the top of your file:
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
I'm searching for a good ANSI C library for Aspect-Oriented Programming.
Some desired features are:
Accessing and modifying arguments of the target function.
Making the target function return and controlling the return value.
I found aspeCt C (https://sites.google.com/a/gapp.msrg.utoronto.ca/aspectc/home), reading the documentation it seems to have everything I need, but when, following the instructions, I run make to compile and pass the tests, the tests fail.
There is any alternative?
You can try AspectC++
is a project that extends the AspectJ approach to C/C++.
For example if you want to a simple C program using Aspect:
int main() {
printf("world");
}
And then you will have an aspect.cc
before(): execution(int main()) {
printf("Hello ");
}
after(): execution(int main()) {
printf(" from AspectC ! \n");
}
You compile both with > acc hello.ac world.mc
And the result is:
gcc hello.c world.c
>./a.out
Hello world from AspectC !
I am using Windows 7-64 bit.
Borland C++ 5.5 isn't working.
Test file Hello.c
#include<stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
Error E2209 Hello.c 1: Unable to open include file 'stdio.h'
Warning W8065 Hello.c 5: Call to function 'printf' with no prototype in function main
* 1 errors in Compile *
I have already made the bcc32.cfg & ilink.cfg with these configs
bcc32.cfg
-I"c:\Borland\BCC55\include"
-L"c:\Borland\BCC55\lib"
ilink32.cfg
-L"c:\Borland\BCC55\lib"
:confused:
First look for your include and library directory and see whether it is the same as in your borland C directories option