Hi All,
The section is titled Variable-length Argument lists.
May I ask a question about the use of "macros".
To quote K&R.
"The standard header <stdarg.hcontai ns a set of macro definitions
that define how to step through an argument list...... The type
va_list is used to declare a variable...in minprintf..ap
.......The macro va_start initializes ap to point to the first unnamed
argument."
Could anyone help me understand the significance of using macros vs
functions, as I think it is more significant than I realize.
thanks in advance.
Sep 5 '08
45 2007
mdh said:
On Sep 6, 6:02 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
<snip>
>Once you have understood the message, you should fix your code appropriatel y, and recompile.
Hi Richard,
You convinced me **long ago** not to ignore warnings. I think what you
perhaps missed, not that I ignored the warning, but I am trying to
figure out **what** and **why** I am doing with some of the macros.
So, to take your car analogy, it would be like a newly emerged person
from the depths of the Amazon rain forest, who somehow got his license
in England (not sure how far we can stretch this) saying "Why is
there a sign about a blind corner and what's more, what is a blind
corner", and finding out the hard way there is a good reason for
it...and hopefully not becoming undefined in the process!.
In this case, it's more like:
Me: "Drive on the left."
You: "Okay, I'll try driving on the right and see what happens."
Me: "Your funeral, not mine."
I understand your desire to grasp the mechanism behind the va macros. On
most machines, it's pretty simple really - va_list simply keeps track of
the first unused argument. When you call va_arg, telling it the type of
the argument, it yields the argument value and, as a side effect, updates
va_list by the right number of bytes to point to the /next/ argument.
But you don't actually need to know that to write C programs, and in fact
it's better (from a portability perspective) if you *don't* know, or if
you can at least pretend you don't know - because it might work
differently on a different machine.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
On Sun, 7 Sep 2008 01:46:27 -0700 (PDT), mdh <md**@comcast.n etwrote:
>On Sep 7, 1:04*am, Barry Schwarz <schwa...@dqel. comwrote:
>On Sat, 6 Sep 2008 18:16:07 -0700 (PDT), mdh <m...@comcast.n etwrote:
> /*warning: passing argument 1 of minprintf of incompatible pointer type ( int fmt) */
And for some reason you think this can be ignored with impunity?
Barry...come on! Of course I don't think this can be ignored with impunity. I think I can explain your incredulousness . You are
But you executed code that did not compile correctly. Then you asked
why it appeared to work anyway and why your debugger showed something
you didn't expect. In this situation, the only way to get a
reasonable answer to those questions (ignoring whether the questions
are worth asking) is in a group that discusses your system. We can
tell you the behavior is undefined but we cannot tell you why your
debugger showed something (anything?) or why the code seemed to do
what you expected.
>**rightly** concerned with writing correct code. But you **also** understand **why** it is correct. Now imagine if I just corrected something without **understanding ** why it is correct. The code would
You mean that at this stage you still don't understand that the
arguments you pass to a function must match the parameters the
function expects? Ignore the why. Treat it as a language
restriction, no different than defining variables before using them or
only coding executable statements inside a function.
>be correct, but I would be back next week making the same error...well , that's the way I work. I obviously asked in such a way that it was not obvious what I was trying to understand...bu t eventually, thanks to you and others who stuck with me...I understand the concept. In **trying** to understand the concept, I often find it helpful to understand **why** something is wrong. Does that make sense?
There are way too many wrong things to worry about **why** each is
wrong. You cannot add two pointers, you cannot multiply a pointer by
an integer, you cannot convert a pointer to a different type without
taking alignment into consideration, you can pass NULL to free but not
to getc, you can initialize an automatic variable with the result of a
function call but not a static variable, and on and on.
--
Remove del for email
On Sep 7, 10:57*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
mdh said:
On Sep 6, 6:02 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
<snip>
Once you have understood the message, you should fix your code
appropriately, and recompile.
Hi Richard,
You convinced me **long ago** not to ignore warnings..
In this case, it's more like:
Me: "Drive on the left."
You: "Okay, I'll try driving on the right and see what happens."
Me: "Your funeral, not mine."
>
But you don't actually need to know that to write C programs, and in fact
it's better (from a portability perspective) if you *don't* know, or if
you can at least pretend you don't know - because it might work
differently on a different machine.
Richard...thank s for being so patient. I took a good look at a lot of
the discussions over the years in the clc...as I had plenty of time
last night! One thing I realized was that "undefined behavior" has
come up ad nauseum and, understandably, the gusto to explain each time
that once ub occurs...all discussion ends. So I can see how some of my
questions must frustrate sometimes, esp falling into the trap of
trying to discern why something is not working by looking at a result
after ub has occurred. Having said that, it does lead me to ask you
this.
If one sees a diagnostic ( and I specifically mean a warning) , should
I, as you newbie ( not you as the expert) assume that anything after
this is ub ( as far as I can see, a message does not actually use the
term 'ub'), and as such, my questions ought to be directed, if any to
the cause of the diagnostic, as opposed to the result. I think this is
the error I made in this line of questioning, esp when asked to show
code.
Barry Schwarz <sc******@dqel. comwrites:
On Sun, 7 Sep 2008 01:46:27 -0700 (PDT), mdh <md**@comcast.n etwrote:
>>On Sep 7, 1:04Â*am, Barry Schwarz <schwa...@dqel. comwrote:
>>On Sat, 6 Sep 2008 18:16:07 -0700 (PDT), mdh <m...@comcast.n etwrote:
/*warning: passing argument 1 of minprintf of incompatible pointer type ( int fmt) */
And for some reason you think this can be ignored with impunity?
Barry...com e on! Of course I don't think this can be ignored with impunity. I think I can explain your incredulousness . You are
But you executed code that did not compile correctly. Then you asked
why it appeared to work anyway and why your debugger showed something
you didn't expect. In this situation, the only way to get a
reasonable answer to those questions (ignoring whether the questions
are worth asking) is in a group that discusses your system. We can
tell you the behavior is undefined but we cannot tell you why your
debugger showed something (anything?) or why the code seemed to do
what you expected.
Nonsense. Someone will be able to. Possibly there are more people here
using his platform because they are interested in C than populate the
"for that platform group".
So less of the "we".
The reason was, in fact, explained to him in this very thread.
And such practical examples, when contrasted with the mythical systems
we keep hearing of here, make great strides in convincing people WHY
"standard C" is better. It's just a pity too many of you run off and
hide behind the "we" and "off topic" rather than compare and contrast
REAL systems in the Standard C arena. Now *that* would be helpful to
people. Real people. With real compilers and platforms. And real
deadlines. And real issues.
On Sep 7, 11:20*am, Barry Schwarz <schwa...@dqel. comwrote:
**understanding ** why it is correct. The code would
You mean that at this stage you still don't understand that the
arguments you pass to a function must match the parameters the
function expects?
Barry, I appreciate all the help you have given. As to the specific
question above, I have to defend myself. I **thought** that the
arguments and parameters **did** match, as I conveniently ignored the
warning...which should be read as not quite understanding the
importance and gravity of ignoring a diagnostic. Hopefully, I will not
make that mistake again. However, if I ever do, I am sure it will be
pointed out again, with even greater gusto !! :-) ( see my answer
that I have just given to Richard, before I saw yours).
mdh <md**@comcast.n etwrites:
On Sep 7, 11:20Â*am, Barry Schwarz <schwa...@dqel. comwrote:
>**understandin g** why it is correct. The code would
You mean that at this stage you still don't understand that the arguments you pass to a function must match the parameters the function expects?
Barry, I appreciate all the help you have given. As to the specific
question above, I have to defend myself. I **thought** that the
arguments and parameters **did** match, as I conveniently ignored the
warning...which should be read as not quite understanding the
importance and gravity of ignoring a diagnostic.
Do you ignore road signs too?
On Sep 7, 7:33*pm, mdh <m...@comcast.n etwrote:
On Sep 7, 10:57*am, Richard Heathfield <r...@see.sig.i nvalidwrote:
<snip>
Richard...thank s for being so patient. I took a good look at a lot of
the discussions over the years in the clc...as I had plenty of time
last night! One thing I realized was that "undefined behavior" has
come up ad nauseum and, understandably, the gusto to explain each time
that once ub occurs...all discussion ends. So I can see how some of my
questions must frustrate sometimes, esp falling into the trap of
trying to discern why something is not working by looking at a result
after ub has occurred. Having said that, it does lead me to ask you
this.
If one sees a diagnostic ( and I specifically mean a warning) , should
I, as you newbie ( not you as the expert) assume that anything after
this is ub ( as far as I can see, a message does not actually use the
term 'ub'),
sadly no :-(
implementations are permitted to output diagnostics
for anything they feel the whim to do so.
For instance "unused variable" is poor style but harmless
(unless you meant to use the variable!)
Some compilers complain if you don't use the return value
of a function. Again mostly harmless.
I'm afraid you just have to learn. Parameter mismatch
is one you can't usually ignore.
As a rule of thumb strive for a "clean compile", no errors
or warnings. Sadly this isn't always possible.
Try to understand what the compiler is trying to say and
then decide if you can live with it.
and as such, my questions ought to be directed, if any to
the cause of the diagnostic, as opposed to the result. I think this is
the error I made in this line of questioning, esp when asked to show
code
--
Nick Keighley
mdh wrote:
....
If one sees a diagnostic ( and I specifically mean a warning) , should
I, as you newbie ( not you as the expert) assume that anything after
this is ub ( as far as I can see, a message does not actually use the
term 'ub'), and as such, my questions ought to be directed, if any to
the cause of the diagnostic, as opposed to the result. I think this is
the error I made in this line of questioning, esp when asked to show
code.
It's a good rule of thumb that you should set your compiler to it's
most sensitive warning level, and write your code so that it doesn't
generate any warnings. Like most rules of thumb, you need to be
careful about applying this; some compilers will warn about a great
many things that they don't need to warn about - you should either
turn off those warnings, or ignore them. More importantly, unless you
understand why a warning message was issued, you can't be sure of the
correct way to fix it; some ways of turning off warnings don't do
anything about the actual problem; some ways even make it worse.
Unfortunately, as a newbie you have no easy way to distinguish between
legitimate warnings and unnecessary ones, between the right way to fix
something and the wrong way to fix it.. The hard way, which i strongly
recommend, is that you should always figure out why the warning is
being produced, before you make any decision about how to fix the
problem it's warning you about.
mdh said:
<snip>
If one sees a diagnostic ( and I specifically mean a warning) , should
I, as you newbie ( not you as the expert) assume that anything after
this is ub ( as far as I can see, a message does not actually use the
term 'ub'), and as such, my questions ought to be directed, if any to
the cause of the diagnostic, as opposed to the result.
Yes. If in doubt, assume that a diagnostic message indicates a problem with
your code that must be fixed before proceeding. To fix the code, you must
understand what the diagnostic message is telling you. As I suggested
earlier, this isn't always as obvious as we might like.
If in serious doubt, well, ask.
(Note that the *absence* of diagnostic messages is certainly not a
guarantee that all is well.)
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
On Sep 7, 12:32*pm, jameskuy...@ver izon.net wrote:
mdh wrote:
...
If one sees a diagnostic ( and I specifically mean a warning) , should
I, as you newbie ( not you as the expert) assume.......
Unfortunately, as a newbie you have no easy way to distinguish between
legitimate warnings and unnecessary ones,...... The hard way, which i strongly
recommend, is that you should always figure out why the warning is
being produced, before you make any decision about how to fix the
problem it's warning you about.
Well, Nick and James...that is the **strong** take home message from
this discussion for me. I think it will at the very least, serve to
focus the inquiry if I do ask the clc. Thank you both. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: wenke |
last post by:
Hi,
I am using the following code (see below) from php.net
(http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML
file (encoded in UTF-8). I changed the code slightly so that the cdata
sections will be echoed an not the element names as in the original
example.
In the cdata sections of my XML file I have terms like this:
|
by: Dimitri Tholen |
last post by:
Hi all,
For a project I m working on I am looking for a database with all current
car-makes & models from post-WII till now.
With all the car websites around I am sure this information should be
available somewhere so that I can import it into my MySQL database, but I
simply can't find it.
Does anybody know where I can get my hands on "a" database with this
|
by: Thomas Scheffler |
last post by:
Hi,
I runned in trouble using XALAN for XSL-Transformation.
The following snipplet show what I mean:
<a href="http://blah.com/?test=test&test2=test2">Test1&</a>
<a href="http://blah.com/?test=test&amp;test2=test2">Test2&amp;</a>
This results in the following HTML Code:
|
by: MLH |
last post by:
A programmer developed an AMP (Apache/MySQL/PHP) application
for me. When he was done, he sent me the PHP files and the MySQL
dump file. Now, when I connect to the application on my LAN using
http://192.168.1.106/~mlh/credifree/index.php the AMP app still
thinks the data resides somewhere else. It runs fine - as long as I
leave my LAN's external internet connection up. But if I unplug my
LAN from the world, my app locks up.
Before I...
|
by: TTroy |
last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein
mentioned topics).
K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like
this...
"Newcomers to C are somtimes confused about the difference between a
two-dimensional array and an array of pointers..."
then continues to explain int *b; to be...
| |
by: MPH Computers |
last post by:
Hi I am looking for some help
on Threading and Critical Sections
I have a main thread that controls an event
the event handler creates a new thread for carrying out the work
because the work may not be completed before the event is triggered again
I am trying to add critical sections round the producer & consumer parts of
|
by: António Pinho |
last post by:
Hi,
I have a big problem with an webpart/assembly. i'm trying to connect to sql
server but i get the error "Request for the permission of type
System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.". i've searched for
it and can't find a clear answer. but one thing i'm sure: permissions. if i
change the trust level in the web.config of the sharepoint portal...
|
by: Mike Moore |
last post by:
I'm not very familiar with the web config file. I would like to use the
timeout item in the session state for our connection string, but not use the
stateconnection string and sqlconnectionstring in the sessionstate section.
I have our connection string information in the appsettings section of the
web config file.
Our authenication mode reads -
<authentication mode="Windows" />
<identity impersonate="true" />
|
by: Andrew Wan |
last post by:
How can VBScript code access JScript code variables in the same ASP page?
<SCRIPT LANGAUGE="VBScript">
Dim a
a = 10
</SCRIPT>
<SCRIPT LANGUAGE="JScript">
Response.Write(a);
</SCRIPT>
|
by: Ioannis Vranos |
last post by:
In K&R2 errata page
<http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html>
there are some ambiguous errata, for which I propose solutions. Any
comments are welcome.
Ambiguous errata (mentioned first) of "The C Programming Language" 2nd
Edition errata page
(http://www-db-out.research.bell-labs.com/cm/cs/cbook/2ediffs.html), and
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |