473,406 Members | 2,620 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,406 software developers and data experts.

Should a compiler produce a warning/error for this?

typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int void(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}
Feb 16 '08 #1
10 2300
int void(int argc, char **argv)
oops, err that should be int main(int argc, char **argv)

Feb 16 '08 #2
MisterE wrote:
typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int void(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}
Yes, why would you think otherwise?

--
Ian Collins.
Feb 16 '08 #3
MisterE wrote,hidden in the subject line, where it does not belong)
"Should a compiler produce a warning/error for this?".
Anything worth saying or asking is worth writing in the body of your
message.
typedef struct sg
{
int a;
} G;
int c(G* g)
{
return g->a;
}
int void(int argc, char **argv)
^^^^^^^^
Yes, the compiler should issue a diagnostic for this.
It makes any question about the body of the function irrelevant.
{
G g;
c(g); //<----- instead of c(&g);
}
Feb 16 '08 #4
MisterE wrote:
>int void(int argc, char **argv)

oops, err that should be int main(int argc, char **argv)
Before "MisterE" just left the question out of the body of the text.
This time he has destroyed any context at all, making the above
incomprehensible.

[Restored question and context]
Subject: Should a compiler produce a warning/error for this?

typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int main /* was: void */(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}

[Answer]
Of course the compiler should issue a diagnostic when the type of the
argument is incompatible with the type of the parameter.
If it doesn't, I suspect you have almost all diagnostics turned off.
Turn them on! Now!

Feb 16 '08 #5

"Martin Ambuhl" <ma*****@earthlink.netwrote in message
news:61*************@mid.individual.net...
MisterE wrote:
>>int void(int argc, char **argv)

oops, err that should be int main(int argc, char **argv)

Before "MisterE" just left the question out of the body of the text. This
time he has destroyed any context at all, making the above
incomprehensible.

[Restored question and context]
Subject: Should a compiler produce a warning/error for this?

typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int main /* was: void */(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}

[Answer]
Of course the compiler should issue a diagnostic when the type of the
argument is incompatible with the type of the parameter.
If it doesn't, I suspect you have almost all diagnostics turned off.
Turn them on! Now!
The reason I asked is I have tried 3 compilers and so far none produced any
sort of warning, at least in their default mode.
If the variable isn't a structure, they will however.
Feb 16 '08 #6
MisterE wrote:
>>
typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int main /* was: void */(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}

The reason I asked is I have tried 3 compilers and so far none produced any
sort of warning, at least in their default mode.
If the variable isn't a structure, they will however.
Care to name and shame? Whatever they are, they must be broken.

--
Ian Collins.
Feb 16 '08 #7
"MisterE" <vo***@sometwher.worldwrites:
typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int void(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}
In a later followup, MisterE wrote:
oops, err that should be int main(int argc, char **argv)
and later:
The reason I asked is I have tried 3 compilers and so far none produced any
sort of warning, at least in their default mode.
If the variable isn't a structure, they will however.
I don't doubt your sincerity, but that seems unlikely. In your
initial article, you posted code with a serious syntax error ("int
void" rather than "int main"), obviously a typo. That's no great sin
(we all make mistakes) but it means that the code you posted is not
exactly the same as the code that you actually compiled. You
apparently re-typed the code, and perhaps paraphrased it, when you
posted it here. That turns out to be a remarkably efficient way to
change or delete the small detail that was actually causing whatever
problem you were having.

In my opinion, it's far more likely that the code you compiled without
complaint on three different compilers was significantly different in
some way from the code you posted, than that three different compilers
would fail to catch the type mismatch in the function call.

Please verify again that your code doesn't elicit a complaint, and
then post the *exact* code that you actually compiled. Copy-and-paste
it; don't paraphrase it, and don't re-type it.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 17 '08 #8
Ian Collins wrote:
>
MisterE wrote:
>
typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int main /* was: void */(int argc, char **argv)
{
G g;
c(g); //<----- instead of c(&g);
}
The reason I asked is I have tried 3 compilers and so far none produced any
sort of warning, at least in their default mode.
If the variable isn't a structure, they will however.
Care to name and shame? Whatever they are, they must be broken.
Yes, please do.

Using MSVC, even with minimal warnings (-W0), I get this:

usenet.c
usenet.c(14) : error C2115: 'function' : incompatible types

Using gcc gives:

usenet.c: In function `main':
usenet.c:14: incompatible type for argument 1 of `c'

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Feb 17 '08 #9
On Sun, 17 Feb 2008 14:00:48 -0500, Kenneth Brody wrote:
Ian Collins wrote:
>MisterE wrote:
>>
typedef struct sg
{
int a;
} G;

int c(G* g)
{
return g->a;
}

int main /* was: void */(int argc, char **argv) {
G g;
c(g); //<----- instead of c(&g);
}
The reason I asked is I have tried 3 compilers and so far none
produced any sort of warning, at least in their default mode. If the
variable isn't a structure, they will however.
Care to name and shame? Whatever they are, they must be broken.

Yes, please do.

Using MSVC, even with minimal warnings (-W0), I get this:

usenet.c
usenet.c(14) : error C2115: 'function' : incompatible types

Using gcc gives:

usenet.c: In function `main':
usenet.c:14: incompatible type for argument 1 of `c'
To add:

Using icc:
usenet.c(14): error: argument of type "G" is incompatible with parameter
of type "G *"
usenet.c(14): warning #592: variable "g" is used before its value is set

Using lcc:
Error /home/harald/usenet.c: usenet.c: 14 type error in argument 1 to
`c'; found 'struct sg' expected 'pointer to struct sg'

Using tendra: (significantly shortened)
[...]
Illegal conversion from type 'struct sg' to type 'struct sg *'.
[...]

Using tinycc:
usenet.c:14: cannot cast 'struct sg' to 'struct sg *'

Using Comeau online:
"ComeauTest.c", line 14: error: argument of type "G" is incompatible with
parameter of type "G *"
"ComeauTest.c", line 14: warning: variable "g" is used before its value
is set

Using pcc:
usenet.c, line 14: incompatible types for arg 1
Feb 17 '08 #10
MisterE wrote:
"Martin Ambuhl" <ma*****@earthlink.netwrote
>MisterE wrote:
>>>int void(int argc, char **argv)

oops, err that should be int main(int argc, char **argv)

Before "MisterE" just left the question out of the body of the
text. This time he has destroyed any context at all, making the
above incomprehensible.
.... snip ...
>
The reason I asked is I have tried 3 compilers and so far none
produced any sort of warning, at least in their default mode.
If the variable isn't a structure, they will however.
Martins complaint was not about your question, it was about your
phrasing, failure to quote previous messages, and the general
incomprehensibility of your messages. ANY usenet message should be
understandable in isolation, without the subject line.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

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

Feb 18 '08 #11

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

Similar topics

43
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It...
10
by: Rich Sienkiewicz | last post by:
The C# compiler gives warnings about unused variables. I thin it needs a warning about an unassigned reference. For instance, this compiles without any warnings/errors, but of course blows up when...
11
by: Charles Sullivan | last post by:
I have a number of functions, e.g.: int funct1( int arg1, int arg2, int arg3 ); int funct2( int arg1, int arg2, int arg3 ); int funct3( int arg1, int arg2, int arg3 ); that are called via...
49
by: valentin tihomirov | last post by:
fDeleted = false; uint jobId; foreach (Struct struct in structures) { if (struct.type == JOB) { jobId = struct.id; if (struct.dataType == STATUS) fDeteted = (struct.data & STATUS_DELETED) !=...
2
by: stewart.tootill | last post by:
I ran into a code fragment similar to the following in a production code base - although it was even worse since the class jimlad was a class for doing locking similar to boost::mutex::scoped_lock....
11
by: David Mathog | last post by:
There was an editing error in one of my programs giving this line (two left parentheses, one right): FD_SET((ncmd->cmd_in_fd,&read_set); When compiled with gcc -Wall -pedantic -stc=c99 ...
6
by: David Mathog | last post by:
Do any of you happen to have links to compendiums (or heaven forbid, an actual manual) which maps compiler warnings and errors to examples of actual code problems? In this case I'm specifically...
4
by: Andrus | last post by:
If ExecuteQuery method sets fields, C# 3.5 compiler issues invalid warning at compile time: Field '... .Contents' is never assigned to To reproduce, create class class Entity<T> { public...
24
by: Steven D'Aprano | last post by:
Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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
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.