GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jul-2004, 15:41
mirizar mirizar is offline
New Member
 
Join Date: Jun 2004
Posts: 20
mirizar is on a distinguished road
Question

conflict between printf and stdarg.h va functions


Hi!

I think C is having some conflict between printf and the stdarg.h va functions.

Intro:
I am calling a function called zone() within a program. zone() uses the va_start, va_arg, va_end, etc. functions in stdarg.h. These functions are also used by printf functions.

Issue:
If I comment out a simple print statement from the main program, the main program works fine.
If I leave the statement in, for some reason the function zone() in gets confused…. Even though zone() is called with 5 arguments within the main C program, it sees 6 arguments, the last one being coincidentally the last argument of the print statement. I know that the printf/scanf functions use the variable argument functions used by zone(), so I believe somehow the last element of the print statement is staying in memory the next time the va functions are used.

Is there any reason for this or any workaround?
Thanks,

Michelle
  #2  
Old 08-Jul-2004, 16:16
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by mirizar
Hi!

I think C is having some conflict between printf and the stdarg.h va functions.

Intro:
I am calling a function called zone() within a program. zone() uses the va_start, va_arg, va_end, etc. functions in stdarg.h. These functions are also used by printf functions.

Issue:
If I comment out a simple print statement from the main program, the main program works fine.
If I leave the statement in, for some reason the function zone() in gets confused…. Even though zone() is called with 5 arguments within the main C program, it sees 6 arguments, the last one being coincidentally the last argument of the print statement. I know that the printf/scanf functions use the variable argument functions used by zone(), so I believe somehow the last element of the print statement is staying in memory the next time the va functions are used.

Is there any reason for this or any workaround?
Thanks,

Michelle

I have never had that problem in similar situations where I have used the va_arg functions. Is there a chance that you can post your zone function and perhaps the pertinent call?
  #3  
Old 08-Jul-2004, 21:23
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,244
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by mirizar
Hi!

I think C is having some conflict between printf and the stdarg.h va functions.

Intro:
I am calling a function called zone() within a program. zone() uses the va_start, va_arg, va_end, etc. functions in stdarg.h. These functions are also used by printf functions.

Issue:
If I comment out a simple print statement from the main program, the main program works fine.
If I leave the statement in, for some reason the function zone() in gets confused…. Even though zone() is called with 5 arguments within the main C program, it sees 6 arguments, the last one being coincidentally the last argument of the print statement. I know that the printf/scanf functions use the variable argument functions used by zone(), so I believe somehow the last element of the print statement is staying in memory the next time the va functions are used.

Is there any reason for this or any workaround?
Thanks,

Michelle

Sounds to me like the wayward pointer problem -- a pointer that's not really what you think it is. You may have to post the entire function that calls zone(), not just the call.
__________________

Age is unimportant -- except in cheese
  #4  
Old 12-Jul-2004, 08:11
mirizar mirizar is offline
New Member
 
Join Date: Jun 2004
Posts: 20
mirizar is on a distinguished road
Hi!

Files are attached below. If I comment uncomment out lines 154-156 in file1.txt, the function zone() in file2.txt sees "S12D_capacity" as a 6th argument.

Any help would be greatly appreciated.

Michelle
Attached Files
File Type: txt file1.txt (20.8 KB, 51 views)
File Type: txt file2.txt (1.7 KB, 45 views)
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 1) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.