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

Home Posts Topics Members FAQ

pointer to structure array

Hello,

I am having some trouble trying to pass a pointer to an structure
array (as function argument), when executing I get seg faults.

The best I could get out from googling was:

#define MAX_GRAPH 256

typedef struct edge{
long delay;
long bandw;
} edge;

edge link[MAX_GRAPH][MAX_GRAPH];

int print_structure (edge *graph[MAX_GRAPH][MAX_GRAPH]){
int i, j;
for(i=0;i<nodes ;i++){
for(j=0;j<nodes ;j++){
printf("[%d][%d].bandw = %d\t\t", i, j, graph[i][j]->bandw); //
SEG FAULT!
printf("[%d][%d].delay = %d\n", i, j, graph[i][j]->delay);
}
}
return 0;
}
int main(int argc, char* argv[]){

....
print_structure (link);
....
}

Could anybody help me spot the problem?

Thanks,

Paulo

Aug 19 '07
12 2271
Mark Bluemel wrote:
¬a\/b wrote:
>On 24 Aug 2007 06:43:22 GMT, Chris Torek wrote:
<snip>
>>
possibly
i'm not enough smart
possibly
all you game with nothing (i think all is easy but there are people
that complicates languages)
with an easy language is possible to write something that in a
difficult language can not to be written

i hope i offend nobody

I'd have to be able to understand what you've written before I could be
offended by it...
I think he is saying that C's rules complicate what would otherwise be easy.
This is the typical reaction to C from someone who knows only one hardware
architecture and fails to understand that the reason behind much of the
intricacy behind some of the rules of C is the desire to maintain maximum
portability of the language. It is also an old language that people only
exposed to modern machines and languages find cruelly primitive or stupid.
It's the default reaction from much of the current alt.lang.asm crowd.

Aug 24 '07 #11
Barry Schwarz wrote:
es******@gmail. com wrote:
>I am having some trouble trying to pass a pointer to an structure
array (as function argument), when executing I get seg faults.

Why do you execute code (the only way to get a seg fault) when the
compiler has already told you that the code is incorrect? If you did
not receive a diagnostic for the constraint violation in your call to
print_structure , you need to up the warning level of your compiler.
Why do you assume that the compiler objected? I can think of
various easy ways to get to such a fault without a compiler squeak.

To the OP: Report your complete code, and someone will diagnose.
Reduce it to at most 200 lines that is compilable, standard, and
exhibits the flaw. For c.l.c. publication, keep linelengths under
72 and use neither tabs nor // comments.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 25 '07 #12
On Thu, 23 Aug 2007 23:58:47 -0400, CBFalconer <cb********@yah oo.com>
wrote:
>Barry Schwarz wrote:
>es******@gmail. com wrote:
>>I am having some trouble trying to pass a pointer to an structure
array (as function argument), when executing I get seg faults.

Why do you execute code (the only way to get a seg fault) when the
compiler has already told you that the code is incorrect? If you did
not receive a diagnostic for the constraint violation in your call to
print_structur e, you need to up the warning level of your compiler.

Why do you assume that the compiler objected? I can think of
various easy ways to get to such a fault without a compiler squeak.
Because, as you carefully chose to omit from your quote, the original
post passed an argument of type
edge (*)[MAX_GRAPH]
to a function that was expecting one of type
edge (*)(*[MAX_GRAPH])

Since there is no implicit conversion between the two types, it is a
constraint violation requiring a diagnostic.

The fact that there are other reasons for receiving a seg fault has no
bearing on whether the code requires a compile time diagnostic.
Remove del for email
Aug 29 '07 #13

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

Similar topics

8
54448
by: Frank Münnich | last post by:
Hi there.. My name is Frank Münnich. I've got a question about pointers that refer to an array of a structure. How do I declare that type? If I have declared a structure struct mystruc { int x,y,z; char a,b,c;
20
2118
by: j0mbolar | last post by:
I was reading page 720 of unix network programming, volume one, second edition. In this udp_write function he does the following: void udp_write(char *buf, <everything else omitted) struct udpiphdr *ui; struct ip *ip; ip = (struct ip *) buf;
11
2125
by: x-pander | last post by:
given the code: <file: c.c> typedef int quad_t; void w0(int *r, const quad_t *p) { *r = (*p); }
204
13124
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
1
9503
by: Tobias | last post by:
Hi! I have a problem which is quite tricky. I need to pass a struct from .NET to a native Win32 DLL. But i just need to pass the pointer to a reference of that struct. With my first struct this worked pretty well, accepting to write unsafe code ;-) But my next struct has an array inside and I don't get it passed over to the DLL correctly. Here my struct in c#:
1
3106
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
7
2811
by: Kathy Tran | last post by:
Hi, Could you please help me how to declare an araay of pointer in C#. In my program I declared an structure public struct SEventQ { public uint uiUserData; public uint uiEvent; public uint uiParam0; public uint uiParam1;
13
2999
by: aegis | last post by:
The following was mentioned by Eric Sosman from http://groups.google.com/group/comp.lang.c/msg/b696b28f59b9dac4?dmode=source "The alignment requirement for any type T must be a divisor of sizeof(T). (Proof: In `T array;' both `array' and `array' must be correctly aligned.) Since `sizeof(unsigned char)' is divisible only by one and since one is a divisor of every type's size, every type is suitably aligned for `unsigned char'."
8
2403
by: Sam | last post by:
I have a situation occuring in my code and I just can't see to figure out why I have an structure called employee that will put all of the employee id's into a char array set to 10 struct Employee { char employeeid; /* id of employee*/
12
3888
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9517
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
9030
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...
1
7537
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
5435
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...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
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.