VC++6 to VC++.NET2002: illegal local function definitions 
Author Message
 VC++6 to VC++.NET2002: illegal local function definitions

Hi all,
I got 7 errors of illegal local function definitions when
I built the following code:
// This is the main project file for VC++ application
project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#pragma unmanaged
using namespace System;

// This is the entry point for this application
int _tmain(void)
{
    // TODO: Please replace the sample code below with
your own.
        ////Console::WriteLine(S"Source        
Code:web.mit.edu/thouis/plucker.c");
/* plucker.c - */

typedef struct {
  double x,y,z;

Quote:
} Vector;

typedef struct {
  Vector U, V;

Quote:
} PLine;

double dot(Vector a, Vector b)
{
  return (a.x * b.x + a.y * b.y + a.z * b.z);

Quote:
}

Vector cross(Vector a, Vector b)
{
  Vector c;
  c.x = a.y * b.z - b.y * a.z;
  c.y = a.z * b.x - b.z * a.x;
  c.z = a.x * b.y - b.x * a.y;
  return (c);

Quote:
}

Vector diff(Vector a, Vector b)
{
  Vector c;
  c.x = a.x - b.x;
  c.y = a.y - b.y;
  c.z = a.z - b.z;
  return (c);

Quote:
}

Vector barycentric(double da, double db, double dc,
                   Vector a, Vector b, Vector c)
{
  Vector q;
  q.x = da * a.x + db * b.x + dc * c.x;
  q.y = da * a.y + db * b.y + dc * c.y;
  q.z = da * a.z + db * b.z + dc * c.z;
  return (q);

Quote:
}

// direction U, point P
PLine make_PLine(Vector U, Vector P)
{
  PLine temp;
  temp.U = U;
  temp.V = cross(temp.U, P);
  return (temp);

Quote:
}

Vector randomvec()
{
  Vector c = {drand48(), drand48(), drand48()};
  return (c);

Quote:
}

int main()
{
  Vector tri0, tri1, tri2;
  PLine edge0, edge1, edge2;

  srand48(time(0));

  tri0 = randomvec();
  tri1 = randomvec();
  tri2 = randomvec();

  edge0 = make_PLine(diff(tri2, tri1), tri1);
  edge1 = make_PLine(diff(tri0, tri2), tri2);
  edge2 = make_PLine(diff(tri1, tri0), tri0);

  while (1) {
    Vector orig, dir, intersect, d;
    PLine ray;
    double w0, w1, w2, tot;

    dir = randomvec();
    orig = randomvec();

    ray = make_PLine(dir, orig);

    w0 = dot(ray.U, edge0.V) + dot(ray.V, edge0.U);
    w1 = dot(ray.U, edge1.V) + dot(ray.V, edge1.U);
    w2 = dot(ray.U, edge2.V) + dot(ray.V, edge2.U);

    tot = 1.0 / (w0 + w1 + w2);
    w0 *= tot;
    w1 *= tot;
    w2 *= tot;

    intersect = barycentric(w0, w1, w2, tri0, tri1, tri2);

    d = diff(intersect, orig);

    // all three of these values should be the same if
the point is on
    // (O + tD)
    printf("%f %f %f\n",
           d.x / dir.x,
           d.y / dir.y,
           d.z / dir.z);
  }

Quote:
}

    return 0;
Quote:
}

/////////////////////////////////////
------ Build started: Project: Plucker3dCoord,
Configuration: Debug Win32 ------

Compiling...
Plucker3dCoord.cpp
Plucker3dCoord.cpp(31) : error C2601: 'dot' : local
function definitions are illegal
Plucker3dCoord.cpp(36) : error C2601: 'cross' : local
function definitions are illegal
Plucker3dCoord.cpp(45) : error C2601: 'diff' : local
function definitions are illegal
Plucker3dCoord.cpp(55) : error C2601: 'barycentric' :
local function definitions are illegal
Plucker3dCoord.cpp(65) : error C2601: 'make_PLine' :
local function definitions are illegal
Plucker3dCoord.cpp(73) : error C2601: 'randomvec' : local
function definitions are illegal
Plucker3dCoord.cpp(79) : error C2601: 'main' : local
function definitions are illegal

Build log was saved
at "file://c:\C++Projects\Plucker3dCoord\Debug\BuildLog.ht
m"
Plucker3dCoord - 7 error(s), 0 warning(s)

---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped

///////////////////////////////////////////
(1) Please help and tell me how to correct the error
C2601 for illegal local function definitions.
(2) I have a hard time to use Microsoft Knowledge Base to
search the error message. Please give me some
instructions to do the error message searching.
Thanks in advance,
Scott  Chang



Wed, 05 Oct 2005 04:24:28 GMT  
 VC++6 to VC++.NET2002: illegal local function definitions

Quote:
> Hi all,
> I got 7 errors of illegal local function definitions when
> I built the following code:
> // This is the entry point for this application
> int _tmain(void)
> {

I think if you remove this line, and move up your return 0; statement so
that it's within your second main function, then it should compile?

Quote:
>   }
    return 0;
> }
>     return 0;
> }

--



Wed, 05 Oct 2005 08:57:20 GMT  
 VC++6 to VC++.NET2002: illegal local function definitions
Thanks, Damit.
I did what you instructed and I got 2 new error messages
(C2065):
    Build: 0 succeeded, 1 failed, 0 skipped

Compiling...
Plucker3dCoord.cpp
Plucker3dCoord.cpp(74) : error C2065: 'drand48' :
undeclared identifier
Plucker3dCoord.cpp(83) : error C2065: 'srand48' :
undeclared identifier

Build log was saved
at "file://c:\C++Projects\Plucker3dCoord\Debug\BuildLog.ht
m"
Plucker3dCoord - 2 error(s), 0 warning(s)

---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped
as I built the following code:
// This is the main project file for VC++ application
project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
///#pragma unmanaged
using namespace System;

// This is the entry point for this application
///int _tmain(void)
///{
    // TODO: Please replace the sample code below with
your own.
        ////Console::WriteLine(S"Source
Code:web.mit.edu/thouis/plucker.c");
/* plucker.c - */

typedef struct {
  double x,y,z;

Quote:
} Vector;

typedef struct {
  Vector U, V;

Quote:
} PLine;

double dot(Vector a, Vector b)
{
  return (a.x * b.x + a.y * b.y + a.z * b.z);

Quote:
}

Vector cross(Vector a, Vector b)
{
  Vector c;
  c.x = a.y * b.z - b.y * a.z;
  c.y = a.z * b.x - b.z * a.x;
  c.z = a.x * b.y - b.x * a.y;
  return (c);

Quote:
}

Vector diff(Vector a, Vector b)
{
  Vector c;
  c.x = a.x - b.x;
  c.y = a.y - b.y;
  c.z = a.z - b.z;
  return (c);

Quote:
}

Vector barycentric(double da, double db, double dc,
                   Vector a, Vector b, Vector c)
{
  Vector q;
  q.x = da * a.x + db * b.x + dc * c.x;
  q.y = da * a.y + db * b.y + dc * c.y;
  q.z = da * a.z + db * b.z + dc * c.z;
  return (q);

Quote:
}

// direction U, point P
PLine make_PLine(Vector U, Vector P)
{
  PLine temp;
  temp.U = U;
  temp.V = cross(temp.U, P);
  return (temp);

Quote:
}

Vector randomvec()
{
  Vector c = {drand48(), drand48(), drand48()};
  return (c);

Quote:
}

int main()
{
  Vector tri0, tri1, tri2;
  PLine edge0, edge1, edge2;

  srand48(time(0));

  tri0 = randomvec();
  tri1 = randomvec();
  tri2 = randomvec();

  edge0 = make_PLine(diff(tri2, tri1), tri1);
  edge1 = make_PLine(diff(tri0, tri2), tri2);
  edge2 = make_PLine(diff(tri1, tri0), tri0);

  while (1) {
    Vector orig, dir, intersect, d;
    PLine ray;
    double w0, w1, w2, tot;

    dir = randomvec();
    orig = randomvec();

    ray = make_PLine(dir, orig);

    w0 = dot(ray.U, edge0.V) + dot(ray.V, edge0.U);
    w1 = dot(ray.U, edge1.V) + dot(ray.V, edge1.U);
    w2 = dot(ray.U, edge2.V) + dot(ray.V, edge2.U);

    tot = 1.0 / (w0 + w1 + w2);
    w0 *= tot;
    w1 *= tot;
    w2 *= tot;

    intersect = barycentric(w0, w1, w2, tri0, tri1, tri2);

    d = diff(intersect, orig);

    // all three of these values should be the same if
the point is on
    // (O + tD)
    printf("%f %f %f\n",
           d.x / dir.x,
           d.y / dir.y,
           d.z / dir.z);
  }
///}

    return 0;

Quote:
}

Please help me again and tell me how to correct them.
Thanks,
Scott  Chang

Quote:
>-----Original Message-----
>> Hi all,
>> I got 7 errors of illegal local function definitions
when
>> I built the following code:

>> // This is the entry point for this application
>> int _tmain(void)
>> {

>I think if you remove this line, and move up your return
0; statement so
>that it's within your second main function, then it
should compile?

>>   }
>    return 0;
>> }
>>     return 0;
>> }
>--

>.



Thu, 06 Oct 2005 00:31:35 GMT  
 VC++6 to VC++.NET2002: illegal local function definitions
Hello,

drand48/srand48 are not standard functions.
But if you need them, you can find source
for them on the net


Quote:
> Thanks, Damit.
> I did what you instructed and I got 2 new error messages
> (C2065):
>     Build: 0 succeeded, 1 failed, 0 skipped

> Compiling...
> Plucker3dCoord.cpp
> Plucker3dCoord.cpp(74) : error C2065: 'drand48' :
> undeclared identifier
> Plucker3dCoord.cpp(83) : error C2065: 'srand48' :
> undeclared identifier

> Build log was saved
> at "file://c:\C++Projects\Plucker3dCoord\Debug\BuildLog.ht
> m"
> Plucker3dCoord - 2 error(s), 0 warning(s)

> ---------------------- Done ----------------------

>     Build: 0 succeeded, 1 failed, 0 skipped
> as I built the following code:
> // This is the main project file for VC++ application
> project
> // generated using an Application Wizard.

> #include "stdafx.h"

> #using <mscorlib.dll>
> #include <tchar.h>
> #include <time.h>
> #include <stdlib.h>
> #include <math.h>
> #include <stdio.h>
> ///#pragma unmanaged
> using namespace System;

> // This is the entry point for this application
> ///int _tmain(void)
> ///{
>     // TODO: Please replace the sample code below with
> your own.
> ////Console::WriteLine(S"Source
> Code:web.mit.edu/thouis/plucker.c");
> /* plucker.c - */

> typedef struct {
>   double x,y,z;
> } Vector;

> typedef struct {
>   Vector U, V;
> } PLine;

> double dot(Vector a, Vector b)
> {
>   return (a.x * b.x + a.y * b.y + a.z * b.z);
> }

> Vector cross(Vector a, Vector b)
> {
>   Vector c;
>   c.x = a.y * b.z - b.y * a.z;
>   c.y = a.z * b.x - b.z * a.x;
>   c.z = a.x * b.y - b.x * a.y;
>   return (c);
> }

> Vector diff(Vector a, Vector b)
> {
>   Vector c;
>   c.x = a.x - b.x;
>   c.y = a.y - b.y;
>   c.z = a.z - b.z;
>   return (c);
> }

> Vector barycentric(double da, double db, double dc,
>                    Vector a, Vector b, Vector c)
> {
>   Vector q;
>   q.x = da * a.x + db * b.x + dc * c.x;
>   q.y = da * a.y + db * b.y + dc * c.y;
>   q.z = da * a.z + db * b.z + dc * c.z;
>   return (q);
> }

> // direction U, point P
> PLine make_PLine(Vector U, Vector P)
> {
>   PLine temp;
>   temp.U = U;
>   temp.V = cross(temp.U, P);
>   return (temp);
> }

> Vector randomvec()
> {
>   Vector c = {drand48(), drand48(), drand48()};
>   return (c);
> }

> int main()
> {
>   Vector tri0, tri1, tri2;
>   PLine edge0, edge1, edge2;

>   srand48(time(0));

>   tri0 = randomvec();
>   tri1 = randomvec();
>   tri2 = randomvec();

>   edge0 = make_PLine(diff(tri2, tri1), tri1);
>   edge1 = make_PLine(diff(tri0, tri2), tri2);
>   edge2 = make_PLine(diff(tri1, tri0), tri0);

>   while (1) {
>     Vector orig, dir, intersect, d;
>     PLine ray;
>     double w0, w1, w2, tot;

>     dir = randomvec();
>     orig = randomvec();

>     ray = make_PLine(dir, orig);

>     w0 = dot(ray.U, edge0.V) + dot(ray.V, edge0.U);
>     w1 = dot(ray.U, edge1.V) + dot(ray.V, edge1.U);
>     w2 = dot(ray.U, edge2.V) + dot(ray.V, edge2.U);

>     tot = 1.0 / (w0 + w1 + w2);
>     w0 *= tot;
>     w1 *= tot;
>     w2 *= tot;

>     intersect = barycentric(w0, w1, w2, tri0, tri1, tri2);

>     d = diff(intersect, orig);

>     // all three of these values should be the same if
> the point is on
>     // (O + tD)
>     printf("%f %f %f\n",
>            d.x / dir.x,
>            d.y / dir.y,
>            d.z / dir.z);
>   }
> ///}

>     return 0;
> }

> Please help me again and tell me how to correct them.
> Thanks,
> Scott  Chang

> >-----Original Message-----
> >> Hi all,
> >> I got 7 errors of illegal local function definitions
> when
> >> I built the following code:

> >> // This is the entry point for this application
> >> int _tmain(void)
> >> {

> >I think if you remove this line, and move up your return
> 0; statement so
> >that it's within your second main function, then it
> should compile?

> >>   }
> >    return 0;
> >> }
> >>     return 0;
> >> }
> >--

> >.



Thu, 06 Oct 2005 11:07:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. local function definitions are illegal

2. local function definitions are illegal

3. Error C2601: Local Function Definition Illegal

4. Error - Local function definitions are illegal

5. VC definition files: exporting functions

6. Can VC++4.2b co-exist with VC++5.0 or VC++6.0

7. error C2601: 'addrtn' : local function definitions are illegal

8. error C2601: 'PreTranslateMessage' : local function definitions are illegal

9. VC 7 Definitions and References

10. VC allows ambiguous definitions?

11. Using preprocessor definitions in VC++5.0

12. error C2601: 'PreTranslateMessage' : local function definitions are illegal

 

 
Powered by phpBB® Forum Software