public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* code workaround for  friend ostream& operator<< (ostream&, Array<T>&);
       [not found] ` <6.2.0.14.2.20050203095348.020f8d18@iplan-mn.corp.adobe.com>
@ 2005-02-06 11:53   ` Morten.Gulbrandsen
  2005-02-06 12:12     ` Morten.Gulbrandsen
  2005-02-06 19:00     ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); *****SOLVED******* Morten.Gulbrandsen
  2005-02-06 12:11   ` Static variable in dll cannot be auto-imported in release, but can in debug version Zahroof Mohamed
       [not found]   ` <42024D78.1010000@starnetworks.us>
  2 siblings, 2 replies; 18+ messages in thread
From: Morten.Gulbrandsen @ 2005-02-06 11:53 UTC (permalink / raw)
  To: gcc-help; +Cc: Eljay Love-Jensen

Hello

something is wrong  with my  gcc  compiler

here is my code

===    snip  ===

template <class T>     // declare the template and the parameter
class Array            // the class being parameterized
{
public:
  // constructors
  Array(int itsSize = DefaultSize);
  Array(const Array &rhs);
  ~Array() { delete [] pType; }
  // operators
  Array& operator=(const Array&);
  T& operator[](int offSet) { return pType[offSet]; }
  const T& operator[](int offSet) const
      { return pType[offSet]; }
  // accessors
  int GetSize() const { return itsSize; }
  friend ostream& operator<< (ostream&, Array<T>&);

private:
  T *pType;
  int  itsSize;
};
template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
  for (int i = 0; i<theArray.GetSize(); i++)
      output << "[" << i << "] " << theArray[i] << endl;
  return output;
}


== snip ===



g++ -ansi -pedantic -Wall -o ostream_operator_problem.out 
ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R 
/opt/sfw/gcc-3/lib/ -lstdc++

g++ -o ostream_operator_problem.out ostream_operator_problem.cpp -L 
/opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++

ostream_operator_problem.cpp:46: warning: friend declaration `std::ostream&
 operator<<(std::ostream&, Array<T>&)' declares a non-template function
ostream_operator_problem.cpp:46: warning: (if this is not what you 
intended,
 make sure the function template has already been declared and add <> 
after
 the function name here) -Wno-non-template-friend disables this warning
Undefined                       first referenced
symbol                             in file

operator<<(std::basic_ostream<char, std::char_traits<char> >&, 
Array<int>&)/var/tmp//ccMap1MM.o

ld: fatal: Symbol referencing errors. No output written to 
ostream_operator_problem.out

collect2: ld returned 1 exit status



Please help

gcc -v
Reading specs from 
/opt/sfw/gcc-3/lib/gcc-lib/i386-pc-solaris2.9/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --prefix=/opt/sfw/gcc-3 
--with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as --without-gnu-ld 
--without-gnu-as --enable-shared
Thread model: posix
gcc version 3.3.2

bash-2.05$ uname -X
System = SunOS
Node = Hirschgraben15-23
Release = 5.9
KernelID = Generic_112234-12
Machine = i86pc
BusType = <unknown>
Serial = <unknown>
Users = <unknown>
OEM# = 0
Origin# = 1
NumCPU = 1




best regards

Morten Gulbrandsen




// Using Operator ostream

#include <iostream>

using namespace std;

const int DefaultSize = 10;

class Animal
{
public:
	Animal(int);
	Animal();
	~Animal() {}
	int GetWeight() const { return itsWeight; }
	void Display() const { cout << itsWeight; }
private:
	int itsWeight;
};

Animal::Animal(int weight):
	itsWeight(weight)
{}

Animal::Animal():
	itsWeight(0)
{}

template <class T>     // declare the template and the parameter
class Array            // the class being parameterized
{
public:
	// constructors
	Array(int itsSize = DefaultSize);
	Array(const Array &rhs);
	~Array() { delete [] pType; }

	// operators
	Array& operator=(const Array&);
	T& operator[](int offSet) { return pType[offSet]; }
	const T& operator[](int offSet) const
		{ return pType[offSet]; }
	// accessors
	int GetSize() const { return itsSize; }

	friend ostream& operator<< (ostream&, Array<T>&);

private:
	T *pType;
	int  itsSize;
};

template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
	for (int i = 0; i<theArray.GetSize(); i++)
		output << "[" << i << "] " << theArray[i] << endl;
	return output;
}

// implementations follow...

// implement the Constructor
template <class T>
Array<T>::Array(int size):
	itsSize(size)
{
	pType = new T[size];
	for (int i = 0; i<size; i++)
		pType[i] = 0;
}

// copy constructor
template <class T>
Array<T>::Array(const Array &rhs)
{
	itsSize = rhs.GetSize();
	pType = new T[itsSize];
	for (int i = 0; i<itsSize; i++)
		pType[i] = rhs[i];
}

// operator=
template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
	if (this == &rhs)
		return *this;
	delete [] pType;
	itsSize = rhs.GetSize();
	pType = new T[itsSize];
	for (int i = 0; i<itsSize; i++)
		pType[i] = rhs[i];
	return *this;
}

int main()
{
	bool Stop = false;       // flag for looping
	int offset, value;
	Array<int> theArray;

	while (!Stop)
	{
		cout << "Enter an offset (0-9) ";
		cout << "and a value. (-1 to stop): " ;
		cin >> offset >> value;

		if (offset < 0)
			break;

		if (offset > 9)
		{
			cout << "***Please use values between 0 and 9.***\n";
			continue;
		}

		theArray[offset] = value;
	}

	cout << "\nHere's the entire array:\n";
	cout << theArray << endl;
	return 0;
}



/*

g++ -ansi -pedantic -Wall -o ostream_operator_problem.out ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++


g++ -o ostream_operator_problem.out ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++


ostream_operator_problem.cpp:46: warning: friend declaration `std::ostream& 
   operator<<(std::ostream&, Array<T>&)' declares a non-template function

ostream_operator_problem.cpp:46: warning: (if this is not what you intended, 
   make sure the function template has already been declared and add <> after 
   the function name here) -Wno-non-template-friend disables this warning
Undefined                       first referenced
 symbol                             in file

operator<<(std::basic_ostream<char, std::char_traits<char> >&, Array<int>&)/var/tmp//ccMap1MM.o

ld: fatal: Symbol referencing errors. No output written to ostream_operator_problem.out

collect2: ld returned 1 exit status






*/


/*
Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.3 (Aug  6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing.  All rights reserved.
MODE:strict errors C++


In strict mode, with -tused, Compile succeeded (but remember, the Comeau online compiler does not link).


*/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-06 18:42     ` Function typedefs have any use? Gabriel Dos Reis
@ 2005-02-06 11:58       ` Kevin P. Fleming
  2005-02-06 12:12         ` Kevin P. Fleming
  2005-02-07  0:01         ` Gabriel Dos Reis
  2005-02-06 18:35       ` Kevin P. Fleming
  1 sibling, 2 replies; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-06 11:58 UTC (permalink / raw)
  To: egcs; +Cc: gcc-help

Gabriel Dos Reis wrote:
"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Eljay Love-Jensen wrote:
| 
| > But the syntax of C doesn't have the language construct of "here's a
| > label (identifier), here's the type of that label, and here's it's
| > body".
<snip>

You mean like this:

      typedef int F(int);
      F f;      /* function "f" taking an int and returning an int. */
Well, I was wrong... it does not work. This specific example works, but 
only because the default return type for a function is "int".

If you try this with a typedef-ed function returning anything but int, 
you'll get errors from the compiler about incompatible definitions of 
the function.

So, that leaves me back at my original quandary: I can create a typedef 
of a function type, and I can use that typedef to declare function 
pointers to hold addresses of compatible functions, but I can't use the 
typedef to actually _declare_ those compatible functions (I have to 
write the prototype of the function to match the typedef, and if I don't 
do it correctly then any errors that the compiler finds will be at 
places where the function's address is assigned to a function pointer, 
not at the function definition itself). Bummer.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Static variable in dll cannot be auto-imported in release, but can in debug version
       [not found] ` <6.2.0.14.2.20050203095348.020f8d18@iplan-mn.corp.adobe.com>
  2005-02-06 11:53   ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); Morten.Gulbrandsen
@ 2005-02-06 12:11   ` Zahroof Mohamed
  2005-02-06 17:43     ` Zahroof Mohamed
  2005-02-09 16:16     ` Fwd: " Zahroof Mohamed
       [not found]   ` <42024D78.1010000@starnetworks.us>
  2 siblings, 2 replies; 18+ messages in thread
From: Zahroof Mohamed @ 2005-02-06 12:11 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

Hi,

I'm new to this group. Couldn't find information regarding this topic
and wondered whether anyone had any pointers.

I'm using gcc3.4.3 with Win 2K. Parinya software's MinGW Developer
Studio as the IDE.

I've written a program in C++ that has global variables (object
factories) stored in dlls. However, when I try to build this program,
the debug version builds alright but the release version bombs because
it says it can't auto-import the variable. Here is an example case
that shows this.

--------------------Configuration: Refrigerant - Debug--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Debug\libRefrigerant.dll.a

Refrigerant.dll - 0 error(s), 0 warning(s)

--------------------Configuration: Refrigerant - Release--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc721):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc748):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\libRefrigerant.dll.a
collect2: ld returned 1 exit status

Refrigerant.dll - 0 error(s), 0 warning(s)


Help, please.

Zahroof M

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-06 11:58       ` Kevin P. Fleming
@ 2005-02-06 12:12         ` Kevin P. Fleming
  2005-02-07  0:01         ` Gabriel Dos Reis
  1 sibling, 0 replies; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-06 12:12 UTC (permalink / raw)
  Cc: gcc-help

Gabriel Dos Reis wrote:
> "Kevin P. Fleming" <kpfleming@starnetworks.us> writes:
> 
> | Eljay Love-Jensen wrote:
> | 
> | > But the syntax of C doesn't have the language construct of "here's a
> | > label (identifier), here's the type of that label, and here's it's
> | > body".

<snip>

> You mean like this:
> 
>       typedef int F(int);
>       F f;      /* function "f" taking an int and returning an int. */

Well, I was wrong... it does not work. This specific example works, but 
only because the default return type for a function is "int".

If you try this with a typedef-ed function returning anything but int, 
you'll get errors from the compiler about incompatible definitions of 
the function.

So, that leaves me back at my original quandary: I can create a typedef 
of a function type, and I can use that typedef to declare function 
pointers to hold addresses of compatible functions, but I can't use the 
typedef to actually _declare_ those compatible functions (I have to 
write the prototype of the function to match the typedef, and if I don't 
do it correctly then any errors that the compiler finds will be at 
places where the function's address is assigned to a function pointer, 
not at the function definition itself). Bummer.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* code workaround for  friend ostream& operator<< (ostream&, Array<T>&);
  2005-02-06 11:53   ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); Morten.Gulbrandsen
@ 2005-02-06 12:12     ` Morten.Gulbrandsen
  2005-02-06 19:00     ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); *****SOLVED******* Morten.Gulbrandsen
  1 sibling, 0 replies; 18+ messages in thread
From: Morten.Gulbrandsen @ 2005-02-06 12:12 UTC (permalink / raw)
  To: gcc-help; +Cc: Eljay Love-Jensen

[-- Attachment #1: Type: text/plain, Size: 2417 bytes --]

Hello

something is wrong  with my  gcc  compiler

here is my code

===    snip  ===

template <class T>     // declare the template and the parameter
class Array            // the class being parameterized
{
public:
   // constructors
   Array(int itsSize = DefaultSize);
   Array(const Array &rhs);
   ~Array() { delete [] pType; }

   // operators
   Array& operator=(const Array&);
   T& operator[](int offSet) { return pType[offSet]; }
   const T& operator[](int offSet) const
       { return pType[offSet]; }
   // accessors
   int GetSize() const { return itsSize; }

   friend ostream& operator<< (ostream&, Array<T>&);

private:
   T *pType;
   int  itsSize;
};

template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
   for (int i = 0; i<theArray.GetSize(); i++)
       output << "[" << i << "] " << theArray[i] << endl;
   return output;
}



== snip ===



g++ -ansi -pedantic -Wall -o ostream_operator_problem.out 
ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R 
/opt/sfw/gcc-3/lib/ -lstdc++


g++ -o ostream_operator_problem.out ostream_operator_problem.cpp -L 
/opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++


ostream_operator_problem.cpp:46: warning: friend declaration `std::ostream&
  operator<<(std::ostream&, Array<T>&)' declares a non-template function

ostream_operator_problem.cpp:46: warning: (if this is not what you 
intended,
  make sure the function template has already been declared and add <> 
after
  the function name here) -Wno-non-template-friend disables this warning
Undefined                       first referenced
symbol                             in file

operator<<(std::basic_ostream<char, std::char_traits<char> >&, 
Array<int>&)/var/tmp//ccMap1MM.o

ld: fatal: Symbol referencing errors. No output written to 
ostream_operator_problem.out

collect2: ld returned 1 exit status



Please help

gcc -v
Reading specs from 
/opt/sfw/gcc-3/lib/gcc-lib/i386-pc-solaris2.9/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --prefix=/opt/sfw/gcc-3 
--with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as --without-gnu-ld 
--without-gnu-as --enable-shared
Thread model: posix
gcc version 3.3.2


bash-2.05$ uname -X
System = SunOS
Node = Hirschgraben15-23
Release = 5.9
KernelID = Generic_112234-12
Machine = i86pc
BusType = <unknown>
Serial = <unknown>
Users = <unknown>
OEM# = 0
Origin# = 1
NumCPU = 1





best regards

Morten Gulbrandsen





[-- Attachment #2: ostream_operator_problem.cpp --]
[-- Type: text/plain, Size: 3514 bytes --]

// Using Operator ostream

#include <iostream>

using namespace std;

const int DefaultSize = 10;

class Animal
{
public:
	Animal(int);
	Animal();
	~Animal() {}
	int GetWeight() const { return itsWeight; }
	void Display() const { cout << itsWeight; }
private:
	int itsWeight;
};

Animal::Animal(int weight):
	itsWeight(weight)
{}

Animal::Animal():
	itsWeight(0)
{}

template <class T>     // declare the template and the parameter
class Array            // the class being parameterized
{
public:
	// constructors
	Array(int itsSize = DefaultSize);
	Array(const Array &rhs);
	~Array() { delete [] pType; }

	// operators
	Array& operator=(const Array&);
	T& operator[](int offSet) { return pType[offSet]; }
	const T& operator[](int offSet) const
		{ return pType[offSet]; }
	// accessors
	int GetSize() const { return itsSize; }

	friend ostream& operator<< (ostream&, Array<T>&);

private:
	T *pType;
	int  itsSize;
};

template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
	for (int i = 0; i<theArray.GetSize(); i++)
		output << "[" << i << "] " << theArray[i] << endl;
	return output;
}

// implementations follow...

// implement the Constructor
template <class T>
Array<T>::Array(int size):
	itsSize(size)
{
	pType = new T[size];
	for (int i = 0; i<size; i++)
		pType[i] = 0;
}

// copy constructor
template <class T>
Array<T>::Array(const Array &rhs)
{
	itsSize = rhs.GetSize();
	pType = new T[itsSize];
	for (int i = 0; i<itsSize; i++)
		pType[i] = rhs[i];
}

// operator=
template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
	if (this == &rhs)
		return *this;
	delete [] pType;
	itsSize = rhs.GetSize();
	pType = new T[itsSize];
	for (int i = 0; i<itsSize; i++)
		pType[i] = rhs[i];
	return *this;
}

int main()
{
	bool Stop = false;       // flag for looping
	int offset, value;
	Array<int> theArray;

	while (!Stop)
	{
		cout << "Enter an offset (0-9) ";
		cout << "and a value. (-1 to stop): " ;
		cin >> offset >> value;

		if (offset < 0)
			break;

		if (offset > 9)
		{
			cout << "***Please use values between 0 and 9.***\n";
			continue;
		}

		theArray[offset] = value;
	}

	cout << "\nHere's the entire array:\n";
	cout << theArray << endl;
	return 0;
}



/*

g++ -ansi -pedantic -Wall -o ostream_operator_problem.out ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++


g++ -o ostream_operator_problem.out ostream_operator_problem.cpp -L /opt/sfw/gcc-3/lib/ -R /opt/sfw/gcc-3/lib/ -lstdc++


ostream_operator_problem.cpp:46: warning: friend declaration `std::ostream& 
   operator<<(std::ostream&, Array<T>&)' declares a non-template function

ostream_operator_problem.cpp:46: warning: (if this is not what you intended, 
   make sure the function template has already been declared and add <> after 
   the function name here) -Wno-non-template-friend disables this warning
Undefined                       first referenced
 symbol                             in file

operator<<(std::basic_ostream<char, std::char_traits<char> >&, Array<int>&)/var/tmp//ccMap1MM.o

ld: fatal: Symbol referencing errors. No output written to ostream_operator_problem.out

collect2: ld returned 1 exit status






*/


/*
Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.3 (Aug  6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing.  All rights reserved.
MODE:strict errors C++


In strict mode, with -tused, Compile succeeded (but remember, the Comeau online compiler does not link).


*/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Static variable in dll cannot be auto-imported in release, but can in debug version
  2005-02-06 12:11   ` Static variable in dll cannot be auto-imported in release, but can in debug version Zahroof Mohamed
@ 2005-02-06 17:43     ` Zahroof Mohamed
  2005-02-09 16:16     ` Fwd: " Zahroof Mohamed
  1 sibling, 0 replies; 18+ messages in thread
From: Zahroof Mohamed @ 2005-02-06 17:43 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

Hi,

I'm new to this group. Couldn't find information regarding this topic
and wondered whether anyone had any pointers.

I'm using gcc3.4.3 with Win 2K. Parinya software's MinGW Developer
Studio as the IDE.

I've written a program in C++ that has global variables (object
factories) stored in dlls. However, when I try to build this program,
the debug version builds alright but the release version bombs because
it says it can't auto-import the variable. Here is an example case
that shows this.

--------------------Configuration: Refrigerant - Debug--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Debug\libRefrigerant.dll.a

Refrigerant.dll - 0 error(s), 0 warning(s)

--------------------Configuration: Refrigerant - Release--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc721):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc748):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\libRefrigerant.dll.a
collect2: ld returned 1 exit status

Refrigerant.dll - 0 error(s), 0 warning(s)


Help, please.

Zahroof M

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-06 18:42     ` Function typedefs have any use? Gabriel Dos Reis
  2005-02-06 11:58       ` Kevin P. Fleming
@ 2005-02-06 18:35       ` Kevin P. Fleming
  2005-02-06 23:10         ` Gabriel Dos Reis
  1 sibling, 1 reply; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-06 18:35 UTC (permalink / raw)
  Cc: gcc-help

Gabriel Dos Reis wrote:
> "Kevin P. Fleming" <kpfleming@starnetworks.us> writes:
> 
> | Eljay Love-Jensen wrote:
> | 
> | > But the syntax of C doesn't have the language construct of "here's a
> | > label (identifier), here's the type of that label, and here's it's
> | > body".

<snip>

> You mean like this:
> 
>       typedef int F(int);
>       F f;      /* function "f" taking an int and returning an int. */

Yes, that's it, and it _does_ work :-)

typedef int F(int);

F f;

f(bar)
{
   return bar * bar;
}

int main()
{
   printf("%d\n", f(6));
}

Running this produces "36", as expected.

Thanks!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
       [not found]   ` <42024D78.1010000@starnetworks.us>
@ 2005-02-06 18:42     ` Gabriel Dos Reis
  2005-02-06 11:58       ` Kevin P. Fleming
  2005-02-06 18:35       ` Kevin P. Fleming
  0 siblings, 2 replies; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-06 18:42 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Eljay Love-Jensen wrote:
| 
| > But the syntax of C doesn't have the language construct of "here's a
| > label (identifier), here's the type of that label, and here's it's
| > body".
| 
| Yeah, that's what I figured.
| 
| > So, no, you'll have to do it "the hard way".
| 
| Agreed. Seems like a rather illogical oversight to be able to able to
| define a "type" for a function but not actually be able to declare
| functions of that "type" (except as pointers to them), but that's
| we've got.

You mean like this:

      typedef int F(int);
      F f;      /* function "f" taking an int and returning an int. */

?

-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: code workaround for  friend ostream& operator<< (ostream&, Array<T>&); *****SOLVED*******
  2005-02-06 11:53   ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); Morten.Gulbrandsen
  2005-02-06 12:12     ` Morten.Gulbrandsen
@ 2005-02-06 19:00     ` Morten.Gulbrandsen
  1 sibling, 0 replies; 18+ messages in thread
From: Morten.Gulbrandsen @ 2005-02-06 19:00 UTC (permalink / raw)
  To: gcc-help

hello,  the problem is solved!

solution:


template <class T>     // declare the template and the parameter
class Array            // the class being parameterized
{
public:
   // constructors
   Array(int itsSize = DefaultSize);
   Array(const Array &rhs);
   ~Array() { delete [] pType; }

   // operators
   Array& operator=(const Array&);
   T& operator[](int offSet) { return pType[offSet]; }
   const T& operator[](int offSet) const
       { return pType[offSet]; }
   // accessors
   int GetSize() const { return itsSize; }

 /**************************<>*****************************/
 friend ostream& operator<< <>  (ostream&, Array<T>&); 
 /**************************<>*****************************/

private:
   T *pType;
   int  itsSize;
};




I got the important help from here

alt.comp.lang.learn.c-c++

On Sat, 05 Feb 2005 17:37:55 +0100, Morten Gulbrandsen wrote:

>>
>>    friend ostream& operator<< (ostream&, Array<T>&);
>> //======================================================//
>
>  
>

The syntax is very confusing. Try:

friend ostream& operator<< <> (ostream&, Array<T>&);


Alwyn














^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-06 18:35       ` Kevin P. Fleming
@ 2005-02-06 23:10         ` Gabriel Dos Reis
  0 siblings, 0 replies; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-06 23:10 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Gabriel Dos Reis wrote:
| > "Kevin P. Fleming" <kpfleming@starnetworks.us> writes:
| > | Eljay Love-Jensen wrote:
| > | | > But the syntax of C doesn't have the language construct of
| > "here's a
| > | > label (identifier), here's the type of that label, and here's it's
| > | > body".
| 
| <snip>
| 
| > You mean like this:
| >       typedef int F(int);
| >       F f;      /* function "f" taking an int and returning an int. */
| 
| Yes, that's it, and it _does_ work :-)
| 
| typedef int F(int);
| 
| F f;
| 
| f(bar)

No, that is not the way you define a function.
You can declare a function with a syntax like variable declaration;
but you can't use that syntax to *define* the function.  You need the
full blown syntax.  You can't get away with that one.

-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-06 11:58       ` Kevin P. Fleming
  2005-02-06 12:12         ` Kevin P. Fleming
@ 2005-02-07  0:01         ` Gabriel Dos Reis
  2005-02-07  2:35           ` Kevin P. Fleming
  1 sibling, 1 reply; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-07  0:01 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

[...]

| So, that leaves me back at my original quandary: I can create a
| typedef of a function type, and I can use that typedef to declare
| function pointers to hold addresses of compatible functions, but I
| can't use the typedef to actually _declare_ those compatible functions

sure, you can use it to declare the function itself.  See the example I
gave. 

But, yes, you can't use it to *define* it.  Think about how you'd
introduce the function parameters.

-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  0:01         ` Gabriel Dos Reis
@ 2005-02-07  2:35           ` Kevin P. Fleming
  2005-02-07  2:53             ` Gabriel Dos Reis
  0 siblings, 1 reply; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-07  2:35 UTC (permalink / raw)
  Cc: gcc-help

Gabriel Dos Reis wrote:

> But, yes, you can't use it to *define* it.  Think about how you'd
> introduce the function parameters.

Right, so it's kind of pointless then, seeing as you have have to repeat 
the entire function prototype when you define it. It seems that it would 
be logical to support defining the function and only supplying the 
parameter names, given that their types are already known from it being 
forward-declared, but C does not have that ability. Too bad :-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  2:35           ` Kevin P. Fleming
@ 2005-02-07  2:53             ` Gabriel Dos Reis
  2005-02-07  3:03               ` Kevin P. Fleming
  0 siblings, 1 reply; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-07  2:53 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Gabriel Dos Reis wrote:
| 
| > But, yes, you can't use it to *define* it.  Think about how you'd
| > introduce the function parameters.
| 
| Right, so it's kind of pointless then, seeing as you have have to

I guess "pointless" is in the eye of beholder.  I've used that ability
quite a lot in some projects, where a large number of functions
sharing the same prototype has to be declared. 

| repeat the entire function prototype when you define it. It seems that
| it would be logical to support defining the function and only
| supplying the parameter names, given that their types are already
| known from it being forward-declared, but C does not have that
| ability. Too bad :-)

Care to make a concrete proposal?  There is no point in complaining
if you can't improve over the situation...

-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  2:53             ` Gabriel Dos Reis
@ 2005-02-07  3:03               ` Kevin P. Fleming
  2005-02-07  3:45                 ` Gabriel Dos Reis
  0 siblings, 1 reply; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-07  3:03 UTC (permalink / raw)
  To: gcc-help

Gabriel Dos Reis wrote:

> I guess "pointless" is in the eye of beholder.  I've used that ability
> quite a lot in some projects, where a large number of functions
> sharing the same prototype has to be declared. 

But you still had to repeat the prototypes when defining the functions, 
so it did not provide as much benefit as it could... the declarations 
automatically change when you modify the typedef, but the function 
definitions don't.

> Care to make a concrete proposal?  There is no point in complaining
> if you can't improve over the situation...

Sure, how would I go about doing that? Obviously it would be a GCC 
extension only, but I think it could be useful.

Something as simple as:

typedef char *f_t(char, char, void *);

f_t f;

f(p1, p2, p3)
{
}

This would define function f, taking three parameters (p1, p2 and p3), 
and the return value type and all parameter types would be as specified 
in the forward declaration of the function. If there is no forward 
declaration, this syntax would generate a compile error. If the number 
of parameter does not match the number parameters specified in the 
forward declaration, this would also generate a compile error. All the 
normally available attributes and modifiers would be available as well 
(static, const, pure, etc.).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  3:45                 ` Gabriel Dos Reis
@ 2005-02-07  3:33                   ` Kevin P. Fleming
  2005-02-07  4:45                     ` Gabriel Dos Reis
  0 siblings, 1 reply; 18+ messages in thread
From: Kevin P. Fleming @ 2005-02-07  3:33 UTC (permalink / raw)
  Cc: gcc-help

Gabriel Dos Reis wrote:

> If you believe you have a solution that actually works, then you have
> the choice between:
> 
>   (1) writing a formal proposal and contact the ISO C commitee;
>   (2) writing a formal proposal and convince the GNU C maintainers
>       that your proposal worths adding to GNU C, and work out the
>       details with them.

I don't think is a big enough issue for me to warrant that much effort 
:-) Certainly there is a lot of function pointer usage in many 
applications, and I think it would be beneficial to be able to define 
both the pointers and the functions themselves using the same typedef, 
but I don't think it's worth introducing potential code parsing problems.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  3:03               ` Kevin P. Fleming
@ 2005-02-07  3:45                 ` Gabriel Dos Reis
  2005-02-07  3:33                   ` Kevin P. Fleming
  0 siblings, 1 reply; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-07  3:45 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Gabriel Dos Reis wrote:
| 
| > I guess "pointless" is in the eye of beholder.  I've used that ability
| > quite a lot in some projects, where a large number of functions
| > sharing the same prototype has to be declared.
| 
| But you still had to repeat the prototypes when defining the

yes.  And I did not find it terribly annoying, compared to what I
would have to come up with.

| functions, so it did not provide as much benefit as it could... the
| declarations automatically change when you modify the typedef, but the
| function definitions don't.
| 
| > Care to make a concrete proposal?  There is no point in complaining
| > if you can't improve over the situation...
| 
| Sure, how would I go about doing that? Obviously it would be a GCC
| extension only, but I think it could be useful.
| 
| Something as simple as:
| 
| typedef char *f_t(char, char, void *);
| 
| f_t f;
| 
| f(p1, p2, p3)

But, now this looks like an old-style function definition, except that
the type of the parameters are not provided -- so you would have to
make sure that you do not introduce a parsing ambiguity!

If you believe you have a solution that actually works, then you have
the choice between:

  (1) writing a formal proposal and contact the ISO C commitee;
  (2) writing a formal proposal and convince the GNU C maintainers
      that your proposal worths adding to GNU C, and work out the
      details with them.


-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Function typedefs have any use?
  2005-02-07  3:33                   ` Kevin P. Fleming
@ 2005-02-07  4:45                     ` Gabriel Dos Reis
  0 siblings, 0 replies; 18+ messages in thread
From: Gabriel Dos Reis @ 2005-02-07  4:45 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@starnetworks.us> writes:

| Gabriel Dos Reis wrote:
| 
| > If you believe you have a solution that actually works, then you have
| > the choice between:
| >   (1) writing a formal proposal and contact the ISO C commitee;
| >   (2) writing a formal proposal and convince the GNU C maintainers
| >       that your proposal worths adding to GNU C, and work out the
| >       details with them.
| 
| I don't think is a big enough issue for me to warrant that much effort
| :-) Certainly there is a lot of function pointer usage in many
| applications, and I think it would be beneficial to be able to define
| both the pointers and the functions themselves using the same typedef,
| but I don't think it's worth introducing potential code parsing
| problems.

I'm glad we share similary conclusions:

   # yes.  And I did not find it terribly annoying, compared to what I
   #  would have to come up with.

;-)

-- Gaby

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Fwd: Static variable in dll cannot be auto-imported in release, but can in debug version
  2005-02-06 12:11   ` Static variable in dll cannot be auto-imported in release, but can in debug version Zahroof Mohamed
  2005-02-06 17:43     ` Zahroof Mohamed
@ 2005-02-09 16:16     ` Zahroof Mohamed
  1 sibling, 0 replies; 18+ messages in thread
From: Zahroof Mohamed @ 2005-02-09 16:16 UTC (permalink / raw)
  To: gcc-help; +Cc: Eljay Love-Jensen

Hi,

I'd sent this message earlier, but it looks like it didn't get
through. I would really appreciate it if someone could offer some
advice.

>>


I'm new to this group. Couldn't find information regarding this topic
and wondered whether anyone had any pointers.

I'm using gcc3.4.3 with Win 2K. Parinya software's MinGW Developer
Studio as the IDE.

I've written a program in C++ that has global variables (object
factories) stored in dlls. However, when I try to build this program,
the debug version builds alright but the release version bombs because
it says it can't auto-import the variable. Here is an example case
that shows this.

--------------------Configuration: Refrigerant - Debug--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Debug\libRefrigerant.dll.a

Refrigerant.dll - 0 error(s), 0 warning(s)

--------------------Configuration: Refrigerant - Release--------------------
Compiling source file(s)...
Refrigerant.cpp
Linking...
Info: resolving _cinput_ by linking to __imp__cinput_ (auto-import)
Info: resolving ZAPP::CZObj::ZObjFactory      by linking to
__imp___ZN4ZAPP5CZObj11ZObjFactoryE (auto-import)
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc721):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\Refrigerant.o(.text+0xc748):Refrigerant.cpp:
variable 'ZAPP::CZObj::ZObjFactory' can't be auto-imported. Please
read the documentation for ld's --enable-auto-import for details.
Creating library file:
C:\Zahroof\EAZ\ZObj\Refrigerant\Release\libRefrigerant.dll.a
collect2: ld returned 1 exit status

Refrigerant.dll - 0 error(s), 0 warning(s)

Help, please.

Zahroof M

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-02-09  0:41 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4202465E.5020102@starnetworks.us>
     [not found] ` <6.2.0.14.2.20050203095348.020f8d18@iplan-mn.corp.adobe.com>
2005-02-06 11:53   ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); Morten.Gulbrandsen
2005-02-06 12:12     ` Morten.Gulbrandsen
2005-02-06 19:00     ` code workaround for friend ostream& operator<< (ostream&, Array<T>&); *****SOLVED******* Morten.Gulbrandsen
2005-02-06 12:11   ` Static variable in dll cannot be auto-imported in release, but can in debug version Zahroof Mohamed
2005-02-06 17:43     ` Zahroof Mohamed
2005-02-09 16:16     ` Fwd: " Zahroof Mohamed
     [not found]   ` <42024D78.1010000@starnetworks.us>
2005-02-06 18:42     ` Function typedefs have any use? Gabriel Dos Reis
2005-02-06 11:58       ` Kevin P. Fleming
2005-02-06 12:12         ` Kevin P. Fleming
2005-02-07  0:01         ` Gabriel Dos Reis
2005-02-07  2:35           ` Kevin P. Fleming
2005-02-07  2:53             ` Gabriel Dos Reis
2005-02-07  3:03               ` Kevin P. Fleming
2005-02-07  3:45                 ` Gabriel Dos Reis
2005-02-07  3:33                   ` Kevin P. Fleming
2005-02-07  4:45                     ` Gabriel Dos Reis
2005-02-06 18:35       ` Kevin P. Fleming
2005-02-06 23:10         ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).