473,399 Members | 3,919 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,399 software developers and data experts.

array to container


Hi all,
I'm one of those with about twenty years of experience writing in C,
who is hacking his way through the paradigm shift toward C++, so bear
with me here...

I'm trying to figure out the 'least evil' way of dealing with the
following situation. I have a library of functions written in C (as
it happens, it's an encryption library), which is written in C. A
large number of the functions in that library expect arguments of type
'unsigned char *', i.e. arrays of binary data.

I am writing a C++ application which needs to use this library, but I
am told that 'arrays are evil; bad things will happen to you', so I
looked at the standard containers. If in my application I use vectors
of unsigned char, how do I pass the contained data to the C library
functions? Or should I take the view that if the library wants arrays
of unsigned chars, that's what I should be using and to hell with
being evil?!

I imagine this particular wheel has been invented many many times, so
the wisdom of those who have gone before would be appreciated.

Jun 28 '07 #1
1 1328
On 6/28/2007 12:15 PM, ke***@bytebrothers.co.uk wrote:
Hi all,
I'm one of those with about twenty years of experience writing in C,
who is hacking his way through the paradigm shift toward C++, so bear
with me here...

I'm trying to figure out the 'least evil' way of dealing with the
following situation. I have a library of functions written in C (as
it happens, it's an encryption library), which is written in C. A
large number of the functions in that library expect arguments of type
'unsigned char *', i.e. arrays of binary data.

I am writing a C++ application which needs to use this library, but I
am told that 'arrays are evil; bad things will happen to you', so I
looked at the standard containers. If in my application I use vectors
of unsigned char, how do I pass the contained data to the C library
functions? Or should I take the view that if the library wants arrays
of unsigned chars, that's what I should be using and to hell with
being evil?!

I imagine this particular wheel has been invented many many times, so
the wisdom of those who have gone before would be appreciated.
void your_c_function(unsigned char* p, size_t len);

std::vector<unsigned charvuc;
/// populate vuc;

your_c_function(&vuc[0], vic.size());
Regards,
Stefan
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Jun 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
29
by: shmartonak | last post by:
For maximum portability what should the type of an array index be? Can any integer type be used safely? Or should I only use an unsigned type? Or what? If I'm using pointers to access array...
5
by: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
4
by: bienwell | last post by:
Hi all, Data displayed on the datalist control is bound by the column name of the dataset like this : <%# DataBinder.Eval(Container.DataItem, "title")%> Could I use an element of the array...
6
by: Paminu | last post by:
If I have this struct: #include <stdlib.h> #include <stdio.h> #define KIDS 4 typedef struct test { int x; int y; } container;
18
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and...
4
by: De_Kabal | last post by:
I'm trying to bind a 12x16 array to a repeater to display the information in a table to have certain format. Right now all it does is display all the array elements on individual rows. Does anyone...
7
by: recover | last post by:
class Obj { public: Obj(int a){} } class MyContainer { private: Obj m_obj;
7
by: Unite | last post by:
I have a ArrayList which I add a Array to. How will I access the array from the ArrayList? Example : /*Storing the array*/ String Container = new String; ArrayList arr =new ArrayList(); ...
5
by: zr | last post by:
Hi, Is there a way to initialize a std::tr1::array with a pre-allocated built-in array in a copy-less assignment, such that both will point to the same memory? Vice-versa is easy to do, simply...
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...
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
marktang
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.