•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,609 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,615 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 240 | Replies: 6
![]() |
Hello everyone!
I am stuck on a strange problem -
code -
Now, I want the buffer_out array to be twice the size of stream bitrate. However g++ complains that "size of buffer_out is not constant". I need that buffer size. If I type some integer in it, it is ok. Please help!
I am stuck on a strange problem -
code -
const int buf_size = ((aFormatCtx->bit_rate)*2); for (;;) { static int16_t buffer_out[buf_size]; ring_buf->lockBuf(); ring_buf->read((unsigned char*)buffer_out, buf_size); ring_buf->clearBuf(); ring_buf->unlockBuf(); pthread_mutex_lock(&play_mutex); pthread_cond_signal(&play_cond); pthread_mutex_unlock(&play_mutex); ao_play(device, (char*)buffer_out, buf_size); }
>If I type some integer in it, it is ok.
The error is correct, but not as informative as it could be. Just because you declare a variable to be const doesn't mean that it's guaranteed to be a compile-time constant. In this case,
If any part of the size is calculated at runtime, you have to simulate arrays using pointers and dynamic memory (not recommended), or you have to use a container class that manages the memory for you, such as std::vector.
The error is correct, but not as informative as it could be. Just because you declare a variable to be const doesn't mean that it's guaranteed to be a compile-time constant. In this case,
aFormatCtx->bit_rate probably can't be resolved at compile time, so you can't use the resulting const value as the size of an array.If any part of the size is calculated at runtime, you have to simulate arrays using pointers and dynamic memory (not recommended), or you have to use a container class that manages the memory for you, such as std::vector.
Member of: Beautiful Code Club.
•
•
Join Date: Aug 2007
Posts: 128
Reputation:
Rep Power: 2
Solved Threads: 13
>change into:
wrong. It's not constant because it has expressions that change. Thus you need dynamic memory (allocated with
Right, Narue? *still needs to learn alot*
wrong. It's not constant because it has expressions that change. Thus you need dynamic memory (allocated with
new ) or a type that's managed automatically (like Narue said, std::vector for example).Right, Narue? *still needs to learn alot*
Last edited by hacker9801 : Jul 9th, 2008 at 5:13 am.
Don't yell at me if I'm wrong - I'm thirteen. :)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- fibonacci (C++)
- arrays, addition, and fibonacci (C++)
- How to make computer smarter in Tic Tac Toe? (C)
- MIPS Recursive Programming, Help please! (Assembly)
- How can i make perticular row or perticular cell of a JTable as Editable dynamically (Java)
- Range Of Long?? (C++)
- How to make Java and C++ sockets play nice (Java)
- storing large numbers (C++)
Other Threads in the C++ Forum
- Previous Thread: screwing up function calculation to sort coins
- Next Thread: fopen



Linear Mode