Getting the warning " ISO C90 forbids variable-size array" in gcc compiler while compiling C90 code - gcc-warning

I am compiling my C90 c code in gcc . I am getting the warningISO C90 forbids variable-size array while making the declaration like
int symbols[nc];
Where nc is integer whose value is read from the input file. The values on the input files are varied so i can't keep a constant value. How can I get rid of it? Is it indeed necessary to resolve this warning or we can simply ignore it?
Thanks in advance.

You get that warning because C90 does not support variable length arrays.
You'll either have to switch gcc to C99 mode (which does support vla) , by using the -std=c99 or std=gnu99 command line flag, or rewrite your code to dynamically allocate memory or use a fixed size array.
The warning just tells you that you're not conforming to C90 in this case, but it's otherwise safe. Ignoring a warning should really not be an option though.

Related

Does C11 says anything about empty translation units? If yes, in which section?

I can only find the grammar of translation unit in section 6.9 which is as the follows:
translation-unit: external-declaration
translation-unit external-declaration
From this grammar, it seems that there should be at least one external declarations, which implies that an empty translation unit is not allowed. However, I would like to know what is required for a compiler to do for such a scenario. Can any one point me to the description in C11 if there is one?
Given that definition of a translation-unit, attempting to treat a empty source file as a translation unit results in a syntax error.
Section 5.1.1.3 of the C11 standard (see the N1570 draft) requires a diagnostic for a translation unit that violates a syntax rule or constraint. If the diagnostic is a non-fatal warning and the implementation translates it anyway, the resulting behavior is undefined by omission (4p2). If an implementation fails to issue a diagnostic message, the implementation is non-conforming (at least in the mode in which you invoked it), and the standard has nothing more to say about it.
Although the behavior of a particular implementation doesn't directly answer questions about what the language standard says, here's what gcc and clang do with an empty source file (with options to tell them to attempt to conform to C11):
$ gcc -c -std=c11 -pedantic-errors empty.c
empty.c:1:0: error: ISO C forbids an empty translation unit [-Wpedantic]
$ clang -c -std=c11 -pedantic-errors empty.c
empty.c:1:1: error: ISO C requires a translation unit to contain at least one declaration [-Werror,-Wempty-translation-unit]
^
1 error generated.
$

Netbeans didn't catch error for function that should have return something, not having a return statment

I was surprised to find the compiler gave no warnings or errors when compiling source code containing a function that specified a return value in its signature but didn't actually return anything
e.g.
int foo()
{
}
How can Netbeans be beefed up so it caches these things?
According to this question this is undefined behaviour but I would've thought this is something easy for an IDE to check for.
Also, is there a way to have it displays number of warnings at the bottom of the output window after compiling? For example the way it is by default, a warning could be buried in the amount of irrelevant information and easily missed.
How can Netbeans be beefed up so it caches these things?
Right click to project -> C++ Compiler set Warning Level to More Warnings (below Basic Options).
(Same applies to C Compiler settings)
Or:
Add -Wall to compiler flags.
For a maximum of warnings you can add these: -Wall -Wextra -pedantic
Also, is there a way to have it displays number of warnings at the bottom of the output window after compiling?
I guess there's no number yet, but possible this can help you: How to display all compile errors in Netbeans as a task list?

how I can define variable name with " write " command in fortran

I need to define a variable name for different files inside a Fortran code, while I 'm using this commands
open(unit=5,file="plot.sm")
write(unit=zbin_str,fmt='(f5.2)') zbin
plotname="LF_z"//zbin_str//".ps"
write(5,"dev postencap" plotname)
write(5,"toplabel LF for",//zbin_str//)
I'm receiving these errors :
Syntax error, found '//' when expecting one of: ( * <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> ...
write(5,"toplabel LF for",//zbin_str//)
error #6355: This binary operation is invalid for this data type. [PLOTNAME]
write(5,"dev postencap" plotname)
An arithmetic or LOGICAL type is required in this context.
write(5,"dev postencap" plotname)
How I can define the available name inside the Fortran code??
Thanks
Neither of these lines
write(5,"dev postencap" plotname)
write(5,"toplabel LF for",//zbin_str//)
is well-formed; that's what the compiler is trying to tell you.
Beyond that, I'm not sure what you are trying to do or, therefore, how to fix it. Unless you use keywords your Fortran compiler will understand the 2nd argument in a write statement to be the format specifier in which you want to present the output. I can't see how either "dev postencap" plotname or "toplabel LF for",//zbin_str// can be made into a valid format specifier. Perhaps what you want is
write(5,'(a32)') "dev postencap"//plotname
write(5,'(a32)') "toplabel LF for"//zbin_str
Anything more would be based on guesswork. If this doesn't answer your question explain it more clearly if you can.

How to print value of a constant/macro while debugging in Xcode?

While debugging an iOS application, I know how to print values of objects using :
print "variable name"
po "variable name"
p "integer Variables"
I wanted to know how to print value of a constant while debugging in Xcode?
Is there any command that prints value of a constant? Because, if I use the above commands, the Xcode returns an error saying
error: use of undeclared identifier
Thanks.
Macros (what you get when you #define something) are the domain of the language preprocessor. They are expanded and the expanded value is used when compiling your code.
The debugger doesn't parse your source file, it works off of what's in the binary. So no, you won't be able to view the value of #define macros in the debugger.
Old question, but nowadays compiling with -g3 (GCC) or -fdebug-macro (Clang) will generate debug information for such preprocessor macros.

eclipse Helios sorting - multiline warning description (gcc multiline warnings)

I compile my project with gcc compiler. One of example multi line warning is:
../../Source/Ctrl/SCmd.h: In constructor `STCPCommand::STCPCommand(char)':
../../Source/Ctrl/SCmd.h:273: warning: `STCPCommand::m_pGroup' will be initialized after
../../Source/Ctrl/SCmd.h:133: warning: `const char*STCPCommand::m_pcszSourceInfo'
../../Source/Ctrl/SCmd.h:141: warning: when initialized here
But I can't read it correctly in Problems view (Description).
What I get is 3 different warnings. All lines are in different places - according to sort method.
Is there any way to show this output without sorting ?
Maybe there is some gcc flag that will avoid splitting ?