Keep getting indentifier undefined error in C using any ide - c

So this is my first post. I am preparing for some upcoming college courses on programming, one of them deals with C. I have been teaching myself for a little while and have never encountered this problem before, even though I have used the same code. I am having the issue on any ide that I use, which are MS Visual Studio 2019, and Codeblocks, both 16.01 and 17.12.
The problem is when I try to include an inline function, the compiler brings up an error: identifier "keep_window_open" is undefined, as well as the error: 'keep_window_open':identifier not found.
This never happened until I upgraded Codeblocks from 16.01 to 17.12, so that leads to believe something happened with the compiler or some settings that I don't know about, or how to change.
I have tried going back to Codeblocks 16.01, but still get the same error. All my previous programs, that use the exact same code still compile and run, so I am at a lost and completely frustrated. Enough so to think about changing my major, which I really do not want to do. I enjoy programming. But this problem is killing me.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
inline void keep_window_open() { char ch; scanf("%s", ch); }
int main()
{
printf ("Lets see if this stupid thing works\n");
keep_Window_open();
return 0;
}
The problem is the line of code:
keep_Window_open();
If I comment it out, the program will compile and run, however I can't see it, because all it does is flash and then close the console window. And I need to use this code to see the output window. As I have said I have used this code in many other programs, most of which are much more complex than this, and they all still compile and run. It is only on new projects that I try to create.
I expect the window to stay open until the user presses and enters a key, like it always has before. I am stuck, and would appreciate some input on how to proceed, other than throw myself in front of a bus.

OK, so I was able to solve the issue in CodeBlocks, but not in Visual Studio. I changed the code to have the inline function below the main function, and now when compiled and run in CodeBlocks (17.12) it works exactly like it should, or how I thought it should.
However when I try the same solution in Visual Studio, after putting the inline function below the main function I now get a new error:
'keep_window_open' redefinition basic types
Since I usually use CodeBlocks for C, Visual Studio for C++ and intellij for java, I am not going to worry about this, as long as it works in CodeBlocks I should be OK. However I am curious as to why it work in one IDE and not the other?
I am new to this programming thing, and there is much to learn, and I know virtually nothing about compilers and linkers, as I am focusing on programming techniques and syntax in several different languages.

Related

IOCCC Program compiling errors

code: http://www.ioccc.org/1988/phillipps.c
How do i run this on Coderunner?
I've encountered some compiling problems that i can't solve after searching on the internet.Can someone help me out?
If I am not being informative enough, i'm sorry, but please tell me how i can do better at asking these tech questions.
compiling errors below(i use coderunner)
The program is written in an old dialect of C and is relying on some features now considered broken. Clang (the compiler in question) is not happy about the third argument of main and I don't think you can convince it to accept that.
You can either install gcc, that compiler will accept the code with just warnings. But I don't think coderunner has gcc integration.
Or you can manually unscrew the objectionable bit of the code.
Replace all instances of the word main with mayn in the code and add this bit of code to the beginning of the file:
main() {
mayn(1,0,0);
}
Now you can enjoy the program under clang/coderunner as well.

Cannot compile C programs on CodeBlocks: Undefined reference to 'WinMain#16'

I'm new to C and I'm trying to compile a HelloWorld program. I'm using GNU GCC 4.9.2. I've looked online for many solutions but none of them worked: Every time I compile the program, it hits me with this error:
"Undefined reference to 'WinMain#16'"
Please bear in mind that I HAVE configured the project as a console project, not a windows project and that I have written the main function correctly.
Here's the code:
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
Finally, note that I can successfully compile, build, and run C++ programs with code blocks. For some reason, I can't do the same for C. Additionally, I tried compiling the source file from the command line and the issue still persisted.
Compilation lines:
I solved the problem and I don't know how. I changed the C debugger from gcc to gnu, it gave me a different error. I then changed it back to gcc and it started working randomly. I've been trying to solve this problem for literally 6 hours. Then I try some random nonsense and guess what? it works.
I hate software development.
I love software development.

Matlab crashes with S-function after mdlOutputs

I'm doing my "main" S-function based on the Matlab template with mdlStart mdlOutputs, etc, which communicates with some Ansi C files that I had, and this S-Function is used in Simulink. I compiled the files correctly with mex and in order to debug I'm using Visual Studio 2015. I can set and use breakpoints so everything is working fine.
The problem is, after finishing 'mdlOutputs' function, where all the contents are correctly printed into Matlab the debugging goes into a breakpoint and it goes into 'simulink.c'. After that, the Debug is broken saying that "libmex.pdb" cannot be found.
If I run the Simulink model without Visual Studio in the loop, Matlab just crashes and stops working.
So, any idea on how to check properly where it is giving me an error? Also, do you have any clue on why the process crashes after leaving mdlOutputs and before entering mdlTerminate? What happens in-between these two functions?
I'm using Windows 7, 64-bit and Matlab 2012b (I'm going to try and run it in the 2015b).
I think that I finally found out the solution (even though I quite don't understand it yet).
In the mdlInitializeSizes(SimStruct *S) I substituted ssSetOptions(S, 0); by ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); like it is suggested here.

NetBeans (7.3.1) detects false errors in C

I was trying to play with pointer syntax and I didn't get why I was getting some of the errors I've got. Then when I've tried to compile it with gcc it worked. Is there a way to fix this in NetBeans? It's really annoying to work with false errors...
The code in the picture is:
int (*(*f3(int z))(double ))(float ){
return NULL;
}
This is broken as well yay! :
char (* ( *f())[])(){
return NULL;
}
It seems that cdecl is better in parsing C that this IDE, embarrassing...
This seems to be a bug in Netbeans, there's nothing you can do about it except for reporting it (or fixing it yourself). I think you can't even completely turn off these error indications in Netbeans.
Netbeans has a lot of bugs like this, and other IDEs like Eclipse and Code::Blocks are no better. Although I would think that parsing entered code is the single most important core functionality of an IDE that distinguishes it from an ordinary text editor, they fail surprisingly often when you write some more complicated constructs or use newer language features.

System calls not working in Atmel AVR Studio (with ASF)

I am not getting answers on the AVR Freaks forum and wonder if someone here could help me.
The answer might lie in this SO question, but I am not sure why it would be necessary.
Basically, I have my fist ever Atmel project (AVR studio 6, UC3 processor). The code compiles and links and I can load it to the Atmel board and step through in the debugger.
However, when I try to step over (or run until a breakpoint on the line after) a (valid) call to sprintf(), malloc() or memcpy() (there may be more, which I have not yet discovered), the IDE never returns to the next line of my code, just seeming to hang, or run forever.
[Note] Compiler optimization is off
Do I need to set some linker options (e.g link static (which I tried & it didn't help)? Or build with some library?
What confuses me is that the code compilers and links - what is being linked when I call these standard functions? If I need something else I would expect a compiler or linker error, but get none - so why won't my code run?
Sorry for such a stupid n00nb question, but it is my first micro-controller project.
I discovered that the CPU on my board is an Engineering Sample and not supported by Atmel Studio without a new io.h file.
I sort of figured that out from this question: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106652
Sorry to have troubled you.
what is being linked when I call these standard functions?
The AVR-libc, the implementation of the C standard library ported to the AVR platform.
so why won't my code run?
Compiler errors and runtime errors are not even related. Both of these lines are valid C and they compile, however, on most systems, I'd expect them to dump core:
int x = 1 / 0;
*(int *)0 = 41;
So it might be either:
a bug in the standard library (very unlikely), or
a bug in the online debugger (very unlikely), or
maybe you just expect something that is not supposed to happen?
Instead of trying to step over, what happens if you set a breakpoint at next line after the line you want to step over?
Also, does the operation change if you turn off compiler optimization?

Resources