Sponsored Content
Top Forums Shell Programming and Scripting Detect sprintf and fprintf bad use Post 302397470 by jim mcnamara on Monday 22nd of February 2010 09:01:00 AM
Old 02-22-2010
Do you have the gcc compiler for your platform?
Code:
gcc -Wall mycode.c -o mycode

will list any line and flag as a warning if there is a datatype mismatch between
the format string and the arguments to any of the printf() function family.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to write to file using fprintf in find command...

:D I once again am looking through the man pages and am still working on the find command to fully comprehend all its attributes.. i am a little stuck on a problem with how many options to -print there are and the only two I know how to use are printf and -print.. i can not make heads or tails of... (2 Replies)
Discussion started by: moxxx68
2 Replies

2. Programming

sprintf function

Hi, Can someone help me to figure out whether this code is to write file to /tmp/TIMECLOCK directory or just to asign a variable with "/tmp/TIMECLOCK/name.log_copy.pid" as the string? I am looking into an old C program and could not figure out where in the code that creates... (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Shell Programming and Scripting

ksh scripting sprintf

is there any sprintf function in korn shell scripting, or anything similar to sprintf? (2 Replies)
Discussion started by: gfhgfnhhn
2 Replies

4. Programming

equivalent of sprintf in C++

Hi My requirement is to convert the following to C++ char buffer; sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20)) Since the buffer is of varying length, i cannot hardcode the value as 90. i would like to convert the buffer to string object so that it can receive any... (1 Reply)
Discussion started by: dhanamurthy
1 Replies

5. Programming

fprintf

Could someone explain me the following fprintf format: fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); Why just not use: fprintf(stderr, "ry `%s --help' for more information.\n", program_name) I mean what is _() does? (1 Reply)
Discussion started by: mirusnet
1 Replies

6. Shell Programming and Scripting

sprintf result on perl

Hello, In perl lang, I have create a string (@str) by sprintf but unfortunately when program printed it out, only I could saw a number like 1. Certainly printf doesn't problem. How I can convert a string that are result of sprintf to a common string format??! Thanks in advance. PLEASE HELP ME. (2 Replies)
Discussion started by: Zaxon
2 Replies

7. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

8. Programming

Problem with Sprintf

Hi, I have the below sample code to hash the input number read from file. File will have 16 to 19 digit number and executable hash the number using some logic and returns the hashed value. Each digit in the 16 digit number is converted to a 4 byte value. That if the input is 16digit integer, the... (6 Replies)
Discussion started by: ramkrix
6 Replies

9. Programming

fprintf() gives segmentation fault

Hi, I am using fprintf to write few strings toa file which has been opened in write mode. The syntax is as follows: printf("Testing 7A.\n"); fprintf(out_screen,"%s|%s|%s|%s|%s|\n",var1,var2,var3,var4,var5); printf("Testing 8.\n"); When I execute the code It prints "Testing 7A." then... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

10. Shell Programming and Scripting

Fprintf issue

i had to send a mail an attachment which i got from find command. But i did not get mail but could see the following line in the logs "aliased to fprintf.c". Can someone help me to understand what does it mean?..As this issue is not occuring now, i could not replicate the problem now.Thanks. (1 Reply)
Discussion started by: jesu
1 Replies
CallExt(3)						User Contributed Perl Documentation						CallExt(3)

NAME
PDL::CallExt - call functions in external shared libraries SYNOPSIS
use PDL::CallExt; callext('file.so', 'foofunc', $x, $y); # pass piddles to foofunc() % perl -MPDL::CallExt -e callext_cc file.c DESCRIPTION
callext() loads in a shareable object (i.e. compiled code) using Perl's dynamic loader, calls the named function and passes a list of pid- dle arguments to it. It provides a reasonably portable way of doing this, including compiling the code with the right flags, though it requires simple perl and C wrapper routines to be written. You may prefer to use PP, which is much more portable. See PDL::PP. You should definitely use the latter for a 'proper' PDL module, or if you run in to the limitations of this module. API
callext_cc() allows one to compile the shared objects using Perl's knowledge of compiler flags. The named function (e.g. 'foofunc') must take a list of piddle structures as arguments, there is now way of doing portable general argument construction hence this limitation. In detail the code in the original file.c would look like this: #include "pdlsimple.h" /* Declare simple piddle structs - note this .h file contains NO perl/PDL dependencies so can be used standalone */ int foofunc(int nargs, pdlsimple **args); /* foofunc prototype */ i.e. foofunc() takes an array of pointers to pdlsimple structs. The use is similar to that of "main(int nargs, char **argv)" in UNIX C applications. pdlsimple.h defines a simple N-dimensional data structure which looks like this: struct pdlsimple { int datatype; /* whether byte/int/float etc. */ void *data; /* Generic pointer to the data block */ int nvals; /* Number of data values */ PDL_Long *dims; /* Array of data dimensions */ int ndims; /* Number of data dimensions */ }; (PDL_Long is always a 4 byte int and is defined in pdlsimple.h) This is a simplification of the internal reprensation of piddles in PDL which is more complicated because of threading, dataflow, etc. It will usually be found somewhere like /usr/local/lib/perl5/site_perl/PDL/pdlsimple.h Thus to actually use this to call real functions one would need to right a wrapper. e.g. to call a 2D image processing routine: void myimage_processer(double* image, int nx, int ny); int foofunc(int nargs, pdlsimple **args) { pdlsimple* image = pdlsimple[0]; myimage_processer( image->data, *(image->dims), *(image->dims+1) ); ... } Obviously a real wrapper would include more error and argument checking. This might be compiled (e.g. Linux): cc -shared -o mycode.so mycode.c In general Perl knows how to do this, so you should be able to get away with: perl -MPDL::CallExt -e callext_cc file.c callext_cc() is a function defined in PDL::CallExt to generate the correct compilation flags for shared objects. If their are problems you will need to refer to you C compiler manual to find out how to generate shared libraries. See t/callext.t in the distribution for a working example. It is up to the caller to ensure datatypes of piddles are correct - if not peculiar results or SEGVs will result. FUNCTIONS
callext Call a function in an external library using Perl dynamic loading callext('file.so', 'foofunc', $x, $y); # pass piddles to foofunc() The file must be compiled with dynamic loading options (see "callext_cc"). See the module docs "PDL::Callext" for a description of the API. callext_cc Compile external C code for dynamic loading Usage: % perl -MPDL::CallExt -e callext_cc file.c -o file.so This works portably because when Perl has built in knowledge of how to do dynamic loading on the system on which it was installed. See the module docs "PDL::Callext" for a description of the API. AUTHORS
Copyright (C) Karl Glazebrook 1997. All rights reserved. There is no warranty. You are allowed to redistribute this software / documenta- tion under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribu- tion, the copyright notice should be included in the file. perl v5.8.0 2002-05-31 CallExt(3)
All times are GMT -4. The time now is 05:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy