473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

compile error about void*

200 100+
Hello everyone,


What is wrong with the code, I just want to allocate an array of 100 void* pointers. :-)

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     void** p;
  4.  
  5.     p = new (void*) [100];
  6.  
  7.     return 0;
  8. }
  9.  
>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before '['
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C3409: empty attribute block is not allowed
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ']' before 'constant'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before 'constant'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before ']'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before ']'


thanks in advance,
George
Jan 17 '08 #1
18 2232
Savage
1,764 Expert 1GB
You just remove those '()' around void*,and it should compile.

Expand|Select|Wrap|Line Numbers
  1. p = new void* [100];
Jan 17 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
Use of void* deprecated in C++.
Jan 17 '08 #3
George2
200 100+
Thanks Savage,


Why adding () does not work, which C++ rule is violated?

You just remove those '()' around void*,and it should compile.

Expand|Select|Wrap|Line Numbers
  1. p = new void* [100];

regards,
George
Jan 18 '08 #4
George2
200 100+
Why weaknessforcats?


Any links for this topic and using what to replace void*?

Use of void* deprecated in C++.

regards,
George
Jan 18 '08 #5
Savage
1,764 Expert 1GB
Thanks Savage,


Why adding () does not work, which C++ rule is violated?




regards,
George
Expand|Select|Wrap|Line Numbers
  1. p = new (void*) [100];
this is interpreted by compiler as:

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
because of new operator precedence.
Jan 18 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
p = new (void*) [100];
C++ ain't C.

In C++ new(void*) is a function named new that has a void* arguiment.

Why weaknessforcats?


Any links for this topic and using what to replace void*?

Quote:
Originally Posted by weaknessforcats
Use of void* deprecated in C++.
Function overloading.
Jan 18 '08 #7
Savage
1,764 Expert 1GB
C++ ain't C.

In C++ new(void*) is a function named new that has a void* arguiment.



Function overloading.
What about this then:

Expand|Select|Wrap|Line Numbers
  1. void foo();
  2. void (**p)();
  3.  
  4. p = new (void (*[3])());
  5. p[0] = f;
  6.  
  7. //etc...
Is this interpreted as a overloaded function called new that takes a pointer to the array of generic function pointers,or does it allocate memory for p?
Jan 18 '08 #8
George2
200 100+
Thanks Savage,


I have tried your code can compile. What does the following statement mean?

p = new (void (*[3])());

what is the type of p? Could you interpret the meaning of right side of assignment and left side of assignment please?

What about this then:

Expand|Select|Wrap|Line Numbers
  1. void foo();
  2. void (**p)();
  3.  
  4. p = new (void (*[3])());
  5. p[0] = f;
  6.  
  7. //etc...
Is this interpreted as a overloaded function called new that takes a pointer to the array of generic function pointers,or does it allocate memory for p?

regards,
George
Jan 19 '08 #9
George2
200 100+
Thanks Savage,


Could you explain why the code will be explained to

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
please?

What is unknown_type comes from? What is new operator precedence?

Expand|Select|Wrap|Line Numbers
  1. p = new (void*) [100];
this is interpreted by compiler as:

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
because of new operator precedence.

regards,
George
Jan 19 '08 #10
George2
200 100+
Yes, weaknessforcats.


I agree "In C++ new(void*) is a function named new that has a void* arguiment", and the global new operator function is invoked.

But, does it has anything to do with my question (compile error)? Could you provide more description please?

C++ ain't C.

In C++ new(void*) is a function named new that has a void* arguiment.



Function overloading.

regards,
George
Jan 19 '08 #11
weaknessforcats
9,208 Expert Mod 8TB
I agree "In C++ new(void*) is a function named new that has a void* arguiment", and the global new operator function is invoked.
If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question. You are not allowed to have a function with the same name as a C++ keyword.
Jan 20 '08 #12
George2
200 100+
Thanks weaknessforcats,


In below statements, you mean system global new function?

If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question.

regards,
George
Jan 22 '08 #13
weaknessforcats
9,208 Expert Mod 8TB
No I do not.

new is a keyword. You can't use new as a function name.

I think you may confusing the keyword new with the function
operator new() that is called to allocate memory. I'm not making this up. The new operator calls operator new.
Jan 22 '08 #14
George2
200 100+
Thanks weaknessforcats,


Now I understand you mean operator new. :-)

This is what you mentioned before,

--------------------
If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question.
--------------------

Why if I agree I should answer it by myself? I am confused. So, you mean you think in my question the operator new which takes void* as input argument take effect?

No I do not.

new is a keyword. You can't use new as a function name.

I think you may confusing the keyword new with the function
operator new() that is called to allocate memory. I'm not making this up. The new operator calls operator new.

regards,
George
Jan 23 '08 #15
weaknessforcats
9,208 Expert Mod 8TB
What the compiler sees is new(void*).

That is a function named new that has a void* argument.

That is an error because new is a reserved C++ keyword.

End of discussion.
Jan 23 '08 #16
George2
200 100+
Thanks for your help, weaknessforcats!


I think when adding (), the placement form of new is invoked, right?

What the compiler sees is new(void*).

That is a function named new that has a void* argument.

That is an error because new is a reserved C++ keyword.

End of discussion.

regards,
George
Jan 25 '08 #17
weaknessforcats
9,208 Expert Mod 8TB
That is correct.

Expand|Select|Wrap|Line Numbers
  1. char array[1000];
  2. int* arr = new (array) int[5];
  3.  
The int array is allocated inside the char array.
Jan 25 '08 #18
George2
200 100+
Thanks weaknessforcats!


My question is answered.

That is correct.

Expand|Select|Wrap|Line Numbers
  1. char array[1000];
  2. int* arr = new (array) int[5];
  3.  
The int array is allocated inside the char array.

regards,
George
Jan 27 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
8
by: pavel.orehov | last post by:
Hi, I am using flex and bizon to write HTTP parser. I am passing well flex and bison tools but can't compile their output. ================= Flex file (http_parser.lpp) ============== %{...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
1
by: electrixnow | last post by:
Help!, I need to compile this code with static libs so it run on another XP machine that does'nt have MS Studio installed. When I compile now I get an ERROR: 1>------ Rebuild All started:...
1
by: HugoScripts | last post by:
hi there, as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple...
1
by: Jonas Schneider | last post by:
Heya, donīt know if you know BOINC: itīs a system for distributed computing, therefore distributing work to many computers and creating a little super-computer, see also their homepage:...
12
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
7
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.