Hello
I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4];
T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this.
Is it possible at all?
Any help is really appreciated.
Alex 8 1422
Martin Gieseking wrote: Hello
I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4]; T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this. Is it possible at all?
It is possible. But why would you want to do it?
The code doesn't get clearer or simpler by doing so.
--
Karl Heinz Buchegger kb******@gascad.at
Karl Heinz Buchegger wrote: I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4]; T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this. Is it possible at all?
It is possible. But why would you want to do it? The code doesn't get clearer or simpler by doing so.
Because I have to create lots of dynamic arrays with various compound types
like those above. I don't want to add typedefs for all of them. Ok, maybe
the code becomes less readable but in these special cases I can live with
that.
On Mon, 19 Jan 2004 14:01:36 +0100, Martin Gieseking <mg******@uos.de>
wrote: Hello
I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4]; T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this. Is it possible at all?
Don't do it!
int (*(*t)[3])[4] = new (int (*[10][3])[4]);
You have the choice of 1 nasty line and 1 simple line, or the above
completely hideous line.
I have to ask why you have such strange types anyway - containers
might provide a better approach, depending on your requirements.
Tom
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Martin Gieseking wrote: Karl Heinz Buchegger wrote:
I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4]; T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this. Is it possible at all?
It is possible. But why would you want to do it? The code doesn't get clearer or simpler by doing so.
Because I have to create lots of dynamic arrays with various compound types like those above. I don't want to add typedefs for all of them. Ok, maybe the code becomes less readable but in these special cases I can live with that.
If you think this is better:
void foo( int k )
{
int (*(* *t )[3])[4];
t = new ( int (*(*[k])[3])[4] ) ;
}
int main()
{
foo( 5);
}
But your description suggests, that your design needs some polish.
--
Karl Heinz Buchegger kb******@gascad.at
"Martin Gieseking" <mg******@uos.de> wrote in message
news:bu**********@newsserver.rrzn.uni-hannover.de... Karl Heinz Buchegger wrote:
I've the following piece of code that compiles fine:
typedef int (*(*T)[3])[4]; T *t = new T[k];
Now I would like to avoid the typedef but don't really know how to do this. Is it possible at all? It is possible. But why would you want to do it? The code doesn't get clearer or simpler by doing so.
Because I have to create lots of dynamic arrays with various compound
types like those above. I don't want to add typedefs for all of them. Ok, maybe the code becomes less readable but in these special cases I can live with that.
I'm not sure what sort of variation you are intending but templates might
make it simpler
(i'm not sure you wont need a typename in here somewhere):
template <typename T,int D1,int D2>
struct Confusion
{
typedef T* (*(*TYPE)[D!])[D2];
static TYPE* make(int n) { return new TYPE[n]; }
};
Confusion<T,3,4>::TYPE* x = Confusion<T,3,4>::make(42);
This at least gets rid of all the brackets.
On Mon, 19 Jan 2004 18:16:50 +0000, Nick Hounsome wrote: template <typename T,int D1,int D2> struct Confusion { typedef T* (*(*TYPE)[D!])[D2]; static TYPE* make(int n) { return new TYPE[n]; } };
Confusion<T,3,4>::TYPE* x = Confusion<T,3,4>::make(42);
This at least gets rid of all the brackets.
Good thinking. I would do:
template <typename T,int D1,int D2>
struct Confusion
{
typedef T* (*(*type)[D1])[D2];
};
Confusion<T,3,4>::type *x = new Confusion<T,3,4>::type(42);
HTH,
M4
"Martijn Lievaart" <m@remove.this.part.rtij.nl> wrote in message
news:pa****************************@remove.this.pa rt.rtij.nl... On Mon, 19 Jan 2004 18:16:50 +0000, Nick Hounsome wrote:
template <typename T,int D1,int D2> struct Confusion { typedef T* (*(*TYPE)[D!])[D2]; static TYPE* make(int n) { return new TYPE[n]; } };
Confusion<T,3,4>::TYPE* x = Confusion<T,3,4>::make(42);
This at least gets rid of all the brackets. Good thinking. I would do:
template <typename T,int D1,int D2> struct Confusion { typedef T* (*(*type)[D1])[D2]; };
Confusion<T,3,4>::type *x = new Confusion<T,3,4>::type(42);
I think you meant:
Confusion<T,3,4>::type *x = new Confusion<T,3,4>::type[42]; HTH, M4
On Mon, 19 Jan 2004 21:40:30 +0000, Nick Hounsome wrote: I think you meant: Confusion<T,3,4>::type *x = new Confusion<T,3,4>::type[42];
Duh! Yes, thanks.
M4 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew Au |
last post by:
Dear all,
I am trying to write a piece of software that use Object Oriented design
and implement it with C, I did the following
== In Object.h ==
typedef struct ObjectStructure* Object;
...
|
by: Merrill & Michele |
last post by:
typedef struct
{
WORD versionNumber;
WORD offset;
}
MENUITEMTEMPLATEHEADER;
This is from vol 5 of unnamed platform's programmer's reference. I could
make this conforming by enclosing...
|
by: KK |
last post by:
Hello all,
I have a unsigned char buffer 'buffer' and I need to convert the
first 12 bytes of it into a string. Below is a code that should work,
however, how can I avoid reinterpret_cast...
|
by: PengYu.UT |
last post by:
The following program calls the normal constructor and the copy
constructor.
By calling the copy constuctor is redundandant, all I want is only a
vector of a trial object.
Is there any way to...
|
by: pmm |
last post by:
hi I am repeating my post here plz excuse
i am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent...
|
by: digz |
last post by:
This is a very simplified version of something I am trying to
understand.
The State object holds the strings and maps , and I pass a reference
to State to the process Function which manipulates it...
|
by: Raman |
last post by:
Hi All,
We have an old code base which (unfortunatelty) has some C files that
include other C files:e.g
File.c
=====
#include<stdio.h>
..
void someFunc(){
|
by: nguillot |
last post by:
Hello.
If I have the following classes:
class B {};
typedef B tB;
if A is:
class A
|
by: nguillot |
last post by:
Yes, by redeclaring the tB typedef in A.h:
I really would prefer not to duplicate the typedef, for code
maintenance.
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |