Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7646 Discussions

Help needed simple mistake with enum

JohnNichols
Valued Contributor II
795 Views

One c file as an enum defined 

 

#ifndef YYTOKENTYPE
# define YYTOKENTYPE
  enum yytokentype
  {
    YYEMPTY = -2,
    YYEOF = 0,                     /* "end of file"  */
    YYerror = 256,                 /* error  */
    YYUNDEF = 257,                 /* "invalid token"  */
    GETS = 258,                    /* GETS  */
    RESIZE = 259,                  /* RESIZE  */
    NEXT = 260,                    /* NEXT  */
    FORGET = 261,                  /* FORGET  */
    RESUME = 262,                  /* RESUME  */
    STASH = 263,                   /* STASH  */
    RETRIEVE = 264,                /* RETRIEVE  */

 

The other c file uses the enun elements as return values, but the VS latest tells me it cannot find the elements in the second file.  

I have played with it for hours and I am still lost, do I have to reference the enum in the second c file? 

There are a few other mistakes, those I can fix, but this one has me stumped. 

 

Thanks

 

 

 

0 Kudos
13 Replies
MRajesh_intel
Moderator
767 Views

Hi,

 

Please include "ick.tab.c" wherever you want to use the enum "yytokentype" and also we saw also that there is conflict between variable name of enum in ick.tab.c and ytab.h.

#include "ick.tab.c"

 

Regards

Rajesh.

 

JohnNichols
Valued Contributor II
750 Views

So I got sick of looking at many h and c files, and I have now consolidated the start of the program into one set.  it worked fine in c once I had fixed the inconsistent units between modules, a bool in one place and an int in another.  It also makes it a lot easier to read. 

 

When I add the flex lexer from lex, it wants to be in c++. So I changed the main code from c to c++. 

I had to eliminate another stack of declaration errors. 

Why did this work in c (delete the //) and it needed the definition deleted in c++ to compile - happened quite a few times?

 

 

//long strtol();
		Base = strtol(chp,&chp,10);

 

JohnNichols
Valued Contributor II
747 Views

As I slowly work through the now single h file, I find 

Line 83: /* Comment this out if your version of lex automatically supplies yylineno. */
	Line 165: //extern INT32 yylineno;
	Line 203: static int yylineno;
	Line 639: INT32 	yylineno = 1;
	Line 641: //int yylineno = 1;
	Line 743:   int lineno() const          { return yylineno; }
	Line 751:   int yylineno;       // only maintained if you use %option yylineno
	Line 751:   int yylineno;       // only maintained if you use %option yylineno
	Line 1186: extern int yylineno;
	Line 1187: int yylineno = 1;
Search "yy_init" (5 hits in 1 file of 1 searc

 

How many times do I need to define a variable used through out the program.  1186 and 1187 throw an error. 

jimdempseyatthecove
Black Belt
721 Views

static int foo;/static int foo=nnn;

Declares/defines a "saved" variable to be visible only within the scope in which it is defined.

extern int foo;/extern int foo=nnn;

Declares/defines a "saved" variable that is globally visible.

 

The static variable can only be declared/defined once per scope (compilation unit and/or inside {}'s).

extern int foo; can be declared any time but...

extern int foo=nnn; must be defined only in one instance (per namespace).

 

Not seeing any potential conditional compilation statements, your program contains both an extern and static declaration of a variable with the same name. (this may have been the intention of the obfuscation). This is not necessarily a compile time error as they can represent two distinctly different variables (one in local scope and one in global scope).

Jim Dempsey

 

 

 

JohnNichols
Valued Contributor II
704 Views

As soon as I fix lose and the defines, I will upload the program so you can have a look at it.  

Some of the defines leave me befuddled. 

JohnNichols
Valued Contributor II
699 Views

So I spent all day on it.  Interesting to look at how it is done. 

Here is the code,  the c bat compiles the program using icl.  

I have started to add an output file - goop.out, so I can track the variables and the program stage. 

The const int sub = 301 that the programmers used has some duplicates - 301 in particular so now the case = switch statement is throwing an error, I turned off the sub. 

It runs and then stops, so I need to keep tracking the code.  

It is a nice break from teaching.  I made a s: drive to hold it as a s subst. You need ick-wrap.c syslib.i and beer.i to let it start. 

JohnNichols
Valued Contributor II
699 Views

Jim:  Thought you might try it please.

jimdempseyatthecove
Black Belt
681 Views

John,

Your .zip package contains a shortcut to oneAPI command prompt for IA32...

I didn't install IA32, just Intel64. Is there any reason why you are using IA32?

(Intel is dropping 32-bit support for some of their packages)

Running the shortcut (on my system) results in Error: Product installation not found.

 

Launching oneAPI command prompt for Intel 64 works to get to command prompt without said error message.

However, running c.bat results in: 'icl' is not recognized as an internal or external command

icl is the legacy C++ compiler, icx is now the oneAPI C++ compiler.

 

Issuing: icx prog.cpp /link results in 77 warnings and 11 errors.

*** issuing: icx prog.cpp /link>icxErrors.txt *** results in empty output file (bug in icx in not sending errors to stdout as well as stderr)

 

The dump of the errors from command window:

 

>>==========================

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note:
expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
prog.cpp(4267,3): warning: add explicit braces to avoid dangling else [-Wdangling-else]
else if (lineno / politesse < 3)
^
prog.cpp(4308,7): warning: 'freopen' is deprecated: This function or variable may be unsafe. Consider using freopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
[-Wdeprecated-declarations]
if (freopen(buf2, "r", stdin) == (FILE*)NULL)
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(242,20): note: 'freopen' has been explicitly
marked deprecated here
_Check_return_ _CRT_INSECURE_DEPRECATE(freopen_s)
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(316,55): note:
expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note:
expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
prog.cpp(4349,8): warning: 'strcpy' is deprecated: This function or variable may be unsafe. Consider using strcpy_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
[-Wdeprecated-declarations]
(void)strcpy(buf, argv[optind]);
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\string.h(133,1): note: 'strcpy' has been explicitly
marked deprecated here
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h(748,5): note: expanded from macro
'__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1'
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(_ReturnType, _ReturnPolicy, _DeclSpec, _FuncName, _FuncName##_s, ...
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h(1831,17): note: expanded from macro
'__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX'
_CRT_INSECURE_DEPRECATE(_SecureFuncName) _DeclSpec _ReturnType __cdecl _FuncName(_SalAttributeDs...
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(316,55): note:
expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note:
expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
prog.cpp(4350,8): warning: 'strcat' is deprecated: This function or variable may be unsafe. Consider using strcat_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
[-Wdeprecated-declarations]
(void)strcat(buf, ".c");
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\string.h(90,5): note: 'strcat' has been explicitly
marked deprecated here
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h(748,5): note: expanded from macro
'__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1'
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(_ReturnType, _ReturnPolicy, _DeclSpec, _FuncName, _FuncName##_s, ...
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h(1831,17): note: expanded from macro
'__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX'
_CRT_INSECURE_DEPRECATE(_SecureFuncName) _DeclSpec _ReturnType __cdecl _FuncName(_SalAttributeDs...
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(316,55): note:
expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note:
expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
prog.cpp(4351,13): warning: 'fopen' is deprecated: This function or variable may be unsafe. Consider using fopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
[-Wdeprecated-declarations]
if ((ofp = fopen(buf, "w")) == (FILE*)NULL)
^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\stdio.h(207,20): note: 'fopen' has been explicitly
marked deprecated here
_Check_return_ _CRT_INSECURE_DEPRECATE(fopen_s)
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(316,55): note:
expanded from macro '_CRT_INSECURE_DEPRECATE'
#define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\include\vcruntime.h(306,47): note:
expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
^
prog.cpp(4402,20): warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
enablers[i], i + 1);
^~~~~
prog.cpp(4493,8): warning: format specifies type 'int' but the argument has type 'long long' [-Wformat]
tp - tuples + 1, tp - tuples + 1);
^~~~~~~~~~~~~~~
prog.cpp(4493,25): warning: format specifies type 'int' but the argument has type 'long long' [-Wformat]
tp - tuples + 1, tp - tuples + 1);
^~~~~~~~~~~~~~~
77 warnings and 11 errors generated.

>>================

I will try code later under Intel Parallel Studio 2019 command prompt later using icl

 

Jim Dempsey

 

 

 

 

 

 

JohnNichols
Valued Contributor II
675 Views

Jim:

The interesting issue appears to be the difference in errors and warnings between compilers.  I had not used the icl or icx compiler before and the entire program in the original form threw the errors you show + more in MSVS 2019.  These errors come from icx not icl. 

I was not really paying attention to the 32 or 64 bit, I was just having some fun, and then it got interesting.  Now I have the icl compiler set up using a batch file in a IA32 Intel Window.  I did not realize that there would be such a difference between the compilers, which had me stumped on using MSVS.  But I have a subset of the program running without compiler errors and now I am slowly finishing and adding code. 

The original code in about 10 files for 6000 lines of code is not easy and there are a lot of good comments.   So I started with a fresh program and slowly added the code, fixing the errors as I went.  So now I just have two files, but this turns up interesting combinations of things.

I am down to the last bit, but now there are algorithmic errors that are now popping up - including duplicates of defines in terms of numbers, so SUB is the same number as two others, SUB is one of the commands, but the new compiler throws an error on the two numbers being the same in the case.  This is how the original code came, so maybe old compilers did not pick that up. 

As a teaching tool this is a perfectly good training ground.  I am enjoying myself and I appreciate the help.  

A friend this morning, asked why you would climb into old wooden boat and sail out into the ocean, cause it is there I said. 

The idea from the Intel guru - points me to the need to check the algorithm,  and clean up all of the enums and defines. 

have a good day and now I get to go grading. 

JMN 

But now I have to go back to grading.  

JohnNichols
Valued Contributor II
669 Views

/* Intervene our first-stage lexer. */
extern int lexer(void);
//#define yylex() lexer()

 

The program has this define, it also has a different definition for yylex and lexer. 

So if I comment out this one, I can force the use of lexer,  but this leads to yylex that is a simple switch the input output streams.  

 

I am probably mixing incorrect flex and bison modules with intercal. 

 

lexer loops recursively stuck on a bad char. 

 

Got to love it. 

jimdempseyatthecove
Black Belt
639 Views

John,

I am visiting my son and helping him rehab-ing a house. Just finished up with updating the electrical system (old knob and tub system to newer system with arc fault/ground fault with as little k&t that is too hard to get to. Next big things are a couple of windows, picket fence, lawn, and vent system. Oodles of little things too. Todo list is two pages. Hope to head back home next week. when there, I will have some idle time (at least I hop so)... excepting for a pile of zebra muscles shells clogging the channel to our harbor. Last time I dredged using an excavator and center pivot end loader, this time we will use a pump.

Jim

JohnNichols
Valued Contributor II
623 Views

So you are having fun.  Some one needs to invent a prevention for the ZM's that is the problem of species out of place, a bit like Humans walking out of Africa, it did not help the planet. 

Enjoy.

MRajesh_intel
Moderator
513 Views

Hi John,

 

Could you please let us know whether you need any help in this thread from Intel?

 

If not, then we will no longer be monitoring this thread and this thread will remain open for community discussion.

 

Thanks ,

Rajesh.


Reply