Re: compile error about void*

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thanks Lawrence,


Your solution works. Why adding an additional () will not compile?


regards,
George

"Lawrence Groves" wrote:

"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AAB7C89B-8600-479B-8FC6-8437BF8FBF87@xxxxxxxxxxxxxxxx
Hello everyone,


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

[Code]
int main()
{
void** p;

p = new (void*) [100];

return 0;
}
[/Code]

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 ']'


Hi George,

The brackets are giving you the problem. Try this instead:

void **p;

p = new void *[100];

HTH, Loz.


.



Relevant Pages

  • Re: Reallocate an array (pointers)
    ... char *readr; ... void myadd; ... int main{ ... you have no idea if you will allocate enough space. ...
    (comp.lang.c)
  • Re: two dimensional arrays:
    ... you can create a 2 dimensional array via following ... >> Since your two allocate functions use the same allocation logic, ... both allocation pointers are of type void pointer. ...
    (comp.lang.c)
  • Re: two dimensional arrays:
    ... > Your macro translates as a call to a routine that returns a void** ... > Since your two allocate functions use the same allocation logic, ... > harmless) cast of the second argument to memcpy. ... Again, second function is not part of the discussion, and doesn't even ...
    (comp.lang.c)
  • [PATCH 2/4] sparsemem base: simple NUMA remap space allocator
    ... to allow us to allocate the pgdat's using this mechanism; ... void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags); ... +void *alloc_remap(int nid, unsigned long size) ...
    (Linux-Kernel)
  • Re: size_t or int for malloc-type functions?
    ... I have not worked with 16-bit machines ... want to allocate>32K to a single object. ... void *smalloc{ ... conversion to size_t turns this into a request ...
    (comp.lang.c)