473,803 Members | 3,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing pointer array to function

I have a struct:

typedef struct {
char **user_comments ;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;
void func (char **table)
{
return;
}

int main (void)
{
vorbis_comment vc;
/* This part GCC doesn't like */

func (vc.user_commen ts);

return 0;
}

GCC (3.1) would say that
warning: passing arg 1 of 'func' from incompatible pointer type


But still my code in 'func' (not posted, above is an example) works correctly,
utilizing whole '**table'.

Now what I want to ask is that which is the legal way to make a call of this
kind? Or is it just a bug or "feature" of GCC?
I am compiling with a commandline:

gcc -Wall -pedantic -ansi -mcpu=athlon -ffast-math -O2
Nov 14 '05
11 2074
Tatu Portin wrote:
Ok. First post was wrong. (I thought that simplifying would do the same.
It didn't.)

Here we are:
42:int fprint_comments _formatted
43: ( FILE *tg
44: , const vorbis_comment *vc)
45:{
46: register int i;

....

69: if (flag) {

70: entry = has_str (s_album, vc->user_comment s, vc->comments);

71: val = strpbrk (vc->user_comment s[entry], "=");
72: val++;
73: fprintf (tg, "%s\n", val);
74:
75: flag = 0;
76: }

....

90: return 0;
91:}

gcc -Wall -pedantic -ansi -mcpu=athlon -ffast-math -O2 cdmaker.c
cdmaker_1.o -o cdmaker.exe
cdmaker.c In function 'fprint_comment s_formatted':
cdmaker.c:70 warning: passing arg 2 of 'has_str' from incompatible
pointer type
Function prototypes:
int fprint_comments _formatted
( FILE *tg
, const vorbis_comment *vc);

int has_str
( const char *str
, const char **table
, int ent); /* Number of entries in '**table' */
Struct definition:
typedef struct {
char **user_comments ;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;

Thank you all. The problem was, as you said, the const qualifier.

But is anyone capable of saying why exactly this fails? (with 'const char **table')
Nov 14 '05 #11
Tatu Portin wrote:
...
But is anyone capable of saying why exactly this fails? (with 'const char **table')
...


The reason why type 'T**' is not implicitly convertible to type 'const
T**' (in both C and C++) is explained well in the C++ FAQ

http://www.parashift.com/c++-faq-lit...html#faq-18.15

This is C++ FAQ, but the reasoning applies immediately to C as well. In
short, this conversion, if it was allowed, would create a large hole in
the "wall" of const-correctness checks :) Sometimes it might appear to
be illogical though.

It might be worth noting that C++ allows implicit 'T**' -> 'const T*
const*' conversion. C doesn't.

--
Best regards,
Andrey Tarasevich

Nov 14 '05 #12

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

Similar topics

58
10188
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
8
4119
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
8
29070
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If possible how could one pass these seven values in the array to a function that would check the values. I tried return y but it didn't work
11
4475
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
11
8132
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
2
2197
by: sonaliagr | last post by:
I am trying to update a msg array in function by passing the address but it is showing an error. and also, i want the value of msg array to be accessible to the full code that is inside the main function...I hope i am making sense...Please look at the code and help me in pointing out the error.. #include<stdio.h> #include<stdlib.h> #include<time.h>
3
3496
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/ #include <cstdio> #define MAX_WORD_LEN 80 #define MAX_SIZE 1000
5
2411
by: mshaaban | last post by:
Hello, In my code I have a large static 2D arrays defined as: code: #define LONMAX 1440 #define LATMAX60 480 void main (int argc, char *argv)
20
2187
by: jason | last post by:
Hello, I'm a beginning C programmer and I have a question regarding arrays and finding the number of entries present within an array. If I pass an array of structures to a function, then suddenly I can't use sizeof(array) / sizeof(array) anymore within that function ? Help - What point am I missing ?
8
3508
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
9569
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
10558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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
10069
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...
1
7608
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
5503
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
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
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.