Gcc do not give warning about newline of end of file - c

I tried to code a well known hello world program in c and compiled it using this command :
gcc -Wall -Wextra -pedantic -std=c99 main.c -o exeFile
but I did not get any warning about 5.1.1.2 in C standard (newline at end of file).
I used Vim editor for that and I has also disabled newline settings by typing:
set binary
set noeol
I want to know how can I generate this warning.
used GCC: 5.4.0
This is the source file :
This is the output of compiler:

This was a deliberate decision made in the GCC 4.3.2 timeframe, and carried forward to subsequent releases:
WONTFIX Bug 40474 - gcc 4.3 no longer warns about missing newlines at end of files
RESOLVED Bug 14331 - please add option to suppress warning message "no newline at end of file"

Related

What are compiler flags for?Why won't my code compile?

I wrote a code in C in Ubuntu which checks for balanced brackets in the input given.I compiled it using gcc compiler and I am getting the correct output.This is actually a part of an online course and they are asking me to use the compiler flag
gcc -pipe -O2 -std=c11 filename -lm
I don't think I understand what I am supposed to do so I tried compiling using this flag and my code is not compiling. My question is if my code compiles when I do
gcc filename.c
why isn't it compiling when I do
gcc -pipe -O2 -std=c11 filename -lm
The error message I am getting is :
cc1plus: warning: command line option ‘-std=c11’ is valid for C/ObjC but not for C++
The reason is the file ending. A capital C is interpreted as a C++ file. The solution is to just rename the file like this:
mv filename.C filename.c
My question is if my code compiles when I do gcc filename.C why isn't it compiling when I do gcc -pipe -O2 -std=c11 <filename> -lm
See above. But there are some situations where it would not solve everything. While C11 gives some extensions to previous versions, it's not 100% backwards compatible.
-std=c11 is a correct option
however you need at least gcc 4.7 or higher to have this option
By "<filename>" they mean to substitute in the name of the file you want to compile. Including the literal string "<filename>" will not work.

Compilinig error on WSL when I try to compile a C sourcefile with command line parameters

The compiler fails when compiling the C code below, throwing stray character errors:
#include "stdio.h"  
int main(int argc, char *argv[]) {
     int count;  
     printf("The command line has %d arguments:\n", argc - 1);  
     for(count = 1; count < argc; count++) {  
       printf("%d: %s\n", count, argv[count]);  
      }  
      printf("\n");  
 
      return 0;  
}
Compiler: gcc 5.4.0 20160609 Ubuntu 16.04.3
Screenshot of the error: here
By the way, other C files (like "hello world") can be successfully compiled.
Continuing from my comment, "There are no errors in your code", so any error you receive is either due to your compile string OR is due to you having edited the file in a windows editor that has corrupted the file within WSL.
To compile your code (without warning or error) to the default a.out executable, you can use a simple command line of:
gcc -Wall -Wextra yourfilename.c
note: always compile with warnings enabled, at minimum -Wall -Wextra. You can add many more individual warning options as well as adding -pedantic which will enable a few more.
If you want to add a few additional options, the optimization level and the C-standard to compile against, as well as providing a custom name for your executable instead of the default a.out, you can use:
gcc -Wall -Wextra -pedantic -std=gnu11 -O3 -o yourexename yourfilename.c
Give both a try and report back with the exact error (if any) you receive by editing your question and adding the exact text of the error you receive to your question.
Let me know if you have any further questions.

Question marks when compile C source codes using gcc

We got many question marks ? in the compilation messages as follows when we use gcc to compile our C source. Could you help us, thanks! We used gcc version 4.1.2 20080704 (Red Hat 4.1.2-48).
[source]$ gcc -g -Wall my_c_source.c -o my_c_source
In file included from my_c_source.c:38:
my_c_source.h: In function ?.rint_result?.
my_c_source.h:554: warning: format ?.i?.expects type ?.nt?. but argument 3 has type ?.ong int?
Your locale settings are probably inconsistent with your terminal settings.
gcc uses non-ASCII ‘ (left single quotation mark) and ’ (right single quotation mark) characters in its error messages. Apparently your locale settings are telling gcc that those characters can be used, but your terminal settings are such that they don't show up correctly -- or perhaps you have a font that doesn't support those characters.
If possible, configure your terminal emulator to use UTF-8.
If you can't do that, then setting the $LANG environment variable to "C" will tell gcc to use the ASCII apostrophe character instead:
$ LANG=C gcc -g -Wall my_c_source.c -o my_c_source

How to compile a Linux kernel module using -std=gnu99?

I've recently learned how to program simple character drivers and while playing around with the code I noticed that I get a lot of the following GCC warnings thrown for my C99 code:
warning: ISO C90 forbids mixed declarations and code
I assume this is because the main Linux kernel Makefile is set to compile using a non-C99 standard. I searched around I found this answer here on stackoverflow: How to use make and compile as C99?
So I naturally tried the following in my Makefile:
ccflags-y := -std=gnu99
Unfortunately this didn't silence the GCC warnings. I checked the verbose output of make and verified that GCC is indeed executed with the -std=gnu99 tacked on at the end; so I'm a bit confused.
How do I properly compile a Linux kernel module using the -std=gnu99 option?
EDIT:
I noticed the GCC output shows this option: -Wdeclaration-after-statement. Is this why I am getting the warnings even with the -std=gnu99 option?
It turns out that -std=gnu99 does in fact work; I began seeing errors regarding C99 features after removing the compiler flag. So that meant something else was causing the warnings to print out besides the -std= option.
After parsing through the verbose output via make V=1, I discovered the -Wdeclaration-after-statement option as part of the GCC execution. This was the cause of the ISO C90 mixed declaration warnings I saw.
To disable the ISO C90 warnings, pass this to GCC: -Wno-declaration-after-statement.
For example:
ccflags-y := -std=gnu99 -Wno-declaration-after-statement
You can also specify the flag in your Makefile, if you have one:
FLAGS=-std=gnu99

gcc4.5 on redhat enterprise 3 wield asm warning message

I compiled gcc 4.5.2 on a 64bit Redhat enterprise 3 machine (2.4.21-20.ELsmp, glibc 2.3.2). It compiles ok but with a lot of warning message like
/tmp/ccbGRF5F.s: Assembler messages:
/tmp/ccbGRF5F.s:29: Warning: rest of line ignored; first ignored character is `d'
/tmp/ccbGRF5F.s:33: Warning: rest of line ignored; first ignored character is `d'
/tmp/ccbGRF5F.s:169: Warning: rest of line ignored; first ignored character is `i'
Then I try to compile code with the compiler, still it spits these asm warnings, and I'm not using any asm in my C code. How can I get rid of it? Fix or suppress warning are all fine.
It seems your binutils is too old to handle gcc-4.5's output - and in another project it might outright end in a compile failure. Given RHEL3, that would not surprise me at all.
I'm assuming you're using the command line to compile? adding a "-w" flag to the compile command will suppress all warnings. For example, to compile hello.c without warnings:
gcc hello.c -w -o hello
Will produce the output file "hello", without spitting out any errors.

Resources