Question marks when compile C source codes using gcc - c

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

Related

what does "-std=standard" in gcc info page mean?

I want to know what C language standard is my current installation of gcc following by default. I ran info gcc and it gave -std=standard.
What does -std=standard mean?
I was expecting something like -std=gnu11
OS: linux mint 19.1
gcc version: 7.4.0,
gcc came pre-installed with the OS
I looked into online manual here:
https://gcc.gnu.org/onlinedocs/gcc-7.4.0/gcc/Standards.html#C-Language
but I didn't find any default standard named "standard". Instead I found that it should be "gnu11"
info gcc response:
...
OPTIONS
Option Summary
Here is a summary of all the options, grouped by type. Explanations
are in the following sections.
Overall Options
-c -S -E -o file -x language -v -### --help[=class[,...]]
--target-help --version -pass-exit-codes -pipe -specs=file
-wrapper #file -fplugin=file -fplugin-arg-name=arg
-fdump-ada-spec[-slim] -fada-spec-parent=unit -fdump-go-spec=file
C Language Options
-ansi -std=standard -fgnu89-inline
-fpermitted-flt-eval-methods=standard -aux-info filename
-fallow-parameterless-variadic-functions -fno-asm
...
The word "standard" is in a cursive font. It's a template, it's not a "default gcc standard gcc uses by default", it's a template to be filled by the user with available option, the word "standard" stands there for gnu11 or c11 or for the standard you want to specify.
The same is with -fpermitted-flt-eval-methods=standard or -fno-builtin-function. You should specify the function that gcc should not use builtin for. This is a list of available options for C language in gcc, not list of default options gcc uses.
You can find the standard gcc is using by inspecting __STDC_VERSION__ macro. Or check the documentation. Quoting the link, for gcc 7.2.0:
The default, if no C language dialect options are given, is -std=gnu11.
In the context of -std=standard, standard is meant to represent one of the values listed in the Options Controlling C Dialect. It isn't meant to literally be the string standard; that results in an error:
gcc: error: unrecognized command line option ‘-std=standard’

Get preprocessor output from C through MATLAB mex

I want to get the preprocessor output when compiling my c-code through mex of MATLAB using MinGW64 Compiler (C) so using gcc (right?).
From this post I got that you can do this with pure gcc passing the option -E to gcc.
However I installed gcc through MATLAB app and therefore cannot access it through command line (would also appreciate a command how to do that, without reinstalling MinGW64 and setting it up manually for use with MATLAB).
I tried to do the following assuming that compiler flags are the right way to pass the argument:
mex -c grampc_run.c -I../../include -I../include COMPFLAGS='$COMPFLAGS -E'
This just results in the creation of the object file.
COMPFLAGS is used by the MSCV compiler. The GCC compiler loos at CFLAGS and CXXFLAGS (for C and C++ compilation, respectively). See here. Thus, you should use the following syntax:
mex -c grampc_run.c -I../../include -I../include CFLAGS='$CFLAGS -E'
You might also want to add the -v option to mex. GCC puts the preprocessor output to the standard output, which mex might not show you. With -v it does show you all the output.

Gcc do not give warning about newline of end of file

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"

GCC's UTF-8 output displays incorrectly in Eclipse's build console

I am using Eclipse Mars.1 Release (4.5.1), Win7 SP1 and gcc 5.2.1 (for Cortex architecture, from https://launchpad.net/gcc-arm-embedded). When I try to compile C code encoded in UTF-8 (with BOM), gcc output appears in ANSI, incorrectly of course. My workspace and project have default encoding set to UTF-8.
Adding gcc switch -finput-charset=UTF-8 doesn't change anything.
For sample code (in C):
#error some code here /* diacritics in comment żółćąę */
I get the following result in Eclipse's build console:
arm-none-eabi-gcc -c -mcpu=cortex-m3 -mthumb -Wall -Wstrict-prototypes -Wextra -Wchar-subscripts -Werror=implicit -finput-charset=UTF-8 -g -ggdb3 -fverbose-asm -Wa,-ahlms=./out/logbook_entry_ext2.lst -pipe -MD -MP -MF ./out/logbook_entry_ext2.d -Os -ffunction-sections -fdata-sections -I . -Itests/aceunit/ -Itests/ -Itests/inc/ logbook_entry_ext2.c -o out/logbook_entry_ext2.o
logbook_entry_ext2.c:32:2: error: #error some code here
#error some code here /* diacritics in comment żółćąę */
Files encoded in ANSI (cp1250 in case of my locale - Central European languages) appear correctly.
The same applies to Eclipse's parsers (e.g. 'Problems' window - encoding is broken there in similar way).
I'm sure someone has overcome this problem, because it's silly to use ANSI encoding in 21st century, however most discussions one can google are about encoding strings and identifiers, which are not the case here.
EDIT: My exact question is how to solve this problem in Eclipse, e.g. by changing encoding of Eclipse's build console. Unfortunately I haven't found such setting so far (only for debug consoles).
ANSI isn't an encoding, it's an organization. perhaps you meant ASCII ? either way, that's probably not the issue.
you said your system locale is set to Windows 1250 (codepage 1250). that's really the problem here: you're attempting to use UTF-8 content in an incompatible encoding.
the mojibake you've shown there suggests that's the real problem. if you take "żółćąę" and convert that byte sequence from a CP-1250 to UTF-8 encoding, you end up with "żółćąę". the iconv utility can be used to confirm this:
$ iconv -t UTF-8 -f CP1250 <<<'żółćąę'
żółćąę
i imagine when Eclipse launches a command shell to run tools (like gcc), it uses your native locale (CP-1250). so feeding it UTF-8 content would corrupt things.
the easy answer (imo) is to use UTF-8 everywhere instead of any Windows-specific encoding (like CP-1250). Windows defines this as CP-65001.

Change build output directory when building via terminal

Recently, I found a program that is kind of a mix between an IDE and a text editor. It supports the syntax of the language and it does formatting, but it does not build and run the program for you. I am running Mac OS X 10.6.8. I looked up how to build C code using the Terminal application. The format is:
gcc [file]
Pretty simple. The problem is that I cannot change the directory of where the built file is outputted, nor can I change the name. By default, every file compiled is outputted in the home directory by the name of 'a.out.' How can I specify the output directory and name?
Thanks!
gcc has a -o option to change the output name. You can specify the path there. E.g.:
$ ls
program.c
$ gcc program.c -o program
$ ls
program program.c
$ mkdir bin
$ gcc program.c -o bin/program
$ ls bin
program
$
You should probably also want to know about a few other common options:
-std=c99, -std=gnu99: Use the c99 standard / with gnu extensions.
-Wall, -Wextra, -pedantic: Enable extra warnings.
-O0 -ggdb: Compile with debugging symbols. Look up how to use gdb.
-O2: Compile with processor-independent optimizations. Not compatible with -O0.

Resources