473,791 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

general array in C

Cyn
Hi,
I want to create a general array structure which can hold all types.
Something like this:

struct ARRAY
{
void **array;
size_t size;
};

Work nice to store pointers to structures in it but what is a good way to be
able to both store pointers to structures and primitive types in it?
Oct 24 '06
20 2327
Laurent Deniau <la************ @cern.chwrites:
Keith Thompson wrote:
>Laurent Deniau <la************ @cern.chwrites:
[...]
>>>see my post on "Extremly fast dynamic array implementation" in this group:

http://groups.google.fr/group/comp.l...263e52c0850000

The code is incomplete but I can provide full source code
self-contained (actually it throws exceptions).
Be sure to read that entire thread.

I did.
> The posted code is full of
useless casts,

Could you show me the useless casts in the posted code? I do not say
that the code is perfect, but I do not see useless casts ((void*)
casts are there for information)
>it deliberately doesn't check for allocation errors,

Could you show me what allow you to say that?
>and it *isn't C*. (I think it depends on gcc-specific extensions.)

This is pure C89 code (inline vanishes if OOC_ISO_C < OOC_ISO_C99).

May I suggest you to read again the code?
My apologies. I was referring to the code in the article that started
the thread:

<http://groups.google.c om/group/comp.lang.c/msg/9c9c34004ae180b 5>

not to the code that you posted later:

<http://groups.google.c om/group/comp.lang.c/msg/0b263e52c085000 0>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 26 '06 #21

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

Similar topics

14
2656
by: 2mc | last post by:
Generally speaking, if one had a list (from regular Python) and an array (from Numerical Python) that contained the same number of elements, would a While loop or a For loop process them at the same speed? Or, would the array process faster? I'm new to Python, so my question may expose my ignorance. I appreciate anyone's effort to help me understand. Thanks. It is much appreciated.
2
2015
by: Ross Micheals | last post by:
All I have some general .NET questions that I'm looking for some help with. Some of these questions (like the first) are ones that I've seen various conflicting information on, or questions that I'm not sure are specific anomolies that I'm having, or if they are specific known issues I'm facing. 1. In VB.NET, are arrays stored on the stack or the heap? Why must arrays of value types be boxed in order for them to be (effectively) passed by...
1
1806
by: jason | last post by:
Hello everyone, I have some general questions about the DataTable object, and how it works. Moderately new to C#, I have plenty of texts describing the language, but not so much to reference ADO.NET objects (only the MSDN help files). I have written a C# Class Library that is responsible for encapsulating database information. All the objects work just fine for singleton record insert, update, select, and delete operations. But now we...
4
1152
by: Bill | last post by:
In vbscript and vb6 when you created a array via a join that contained no entries when you did a ubound against that array it returned -1, which of course was very helpful for using it as the upper bound in a for loop. In vb.net, in the same situation the ubound will return 0 and you get an array with 1 null entry. I am missing something here or does this seem totally incompatible?
4
3517
by: Saul775 | last post by:
Hello, all: Just a general question that's been bothering me. Suppose I'd like to create a 2D array of integers -- not using the vector template -- but I need to dynamically create the array as I do not know the dimensions. How could I do this using the "new" operator? For instance, suppose I need to create an array of size row x column, but I don't know the values being passed into the function...
3
1541
by: johnmann56 | last post by:
Hello. I have a small C# program which uses a number of large arrays of double. The program runs fine on my desktop PC which has 2 GB of memory, but when run on my laptop with 512 MB the laptop practically freezes up, from running out of memory. I would therefore like to modify my program so that memory space used by the various arrays can be freed up once I am done with each array. I have tried many things before calling GC.Collect(),...
94
4780
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring that I found inside of a string. Any ideas?
37
7181
by: dmoran21 | last post by:
I am a mathematician trying to write a program in C to do some curve fitting. When I get to the point where I attempt to enter data in my arrays, I get a General Protection Exception error message. What is this and how can I fix it. I am writing in Turbo C++. My source code is below. #include <stdio.h> #include <stdlib.h> #include <math.h>
2
3054
by: subhasree | last post by:
Hi, I am a student of mathematics and quite new to programming in C. I am trying to write a code to construct an array which at every step has to compare the value of the current element with all the existing elements in the array. The code is compiling without error. However whenever I try to run it, I get General Protection Exception. Here is my code: #include <stdio.h> #include <conio.h>
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9995
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.