Sponsored Content
Top Forums Programming Parameter passing to function with void * as Argument Post 302902991 by rupeshkp728 on Friday 23rd of May 2014 11:10:22 AM
Old 05-23-2014
Quote:
Originally Posted by Corona688
Did you try the code or just consider it to look wrong...? Why?

The whole point of using a union, and the whole point of adding type to the beginning of your CS and DS structures, was that they'd all have the same memory layout.

The compiler warns you since it doesn't know you built with these assumptions in mind. You can avoid the warning with a typecast if you want:

Code:
myfunc((S *)&obj);

ok that is fine
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Argument to Function

May i know how to pass an argument to a function in a shell script? Sorry, i din stated that it is in a shell script in my previous post. Means: checkStatus() { ........... } read status; I wanna use the status in the function checkstatus, how... (2 Replies)
Discussion started by: AkumaTay
2 Replies

2. Shell Programming and Scripting

Passing a string parameter to a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (1 Reply)
Discussion started by: fastgoon
1 Replies

3. UNIX for Advanced & Expert Users

Parameter passing in a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (2 Replies)
Discussion started by: fastgoon
2 Replies

4. Programming

How to return void function pointer

Hello all im trying to build function that will return void function pointer what is mean is ( not working ) the main function void * myClass::getFunction(int type){ if(type==1) return &myClass::Test1; if(type==2) return &myClass::Test2; } void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies

5. Shell Programming and Scripting

Passing more than one argument in a function

Hi All, Calling a function with one argument and storing the return value in a shell script is as below:( so far I know) value="`fun_1 "argument1"`" Its working perfectly for me. Can u help me with passing more than one argument and storing the return value Thnaks in advance JS (1 Reply)
Discussion started by: jisha
1 Replies

6. Shell Programming and Scripting

Passing commandline argument to a function

Hi, I have 2 ksh scripts. Script1.ksh contains function definition. script1.ksh function f1() { while getopts a:c: args do case $args in a) ARG1=$OPTARG ;; c) ARG2=$OPTARG ;; \?) echo "Error no valid Arguments passed" esac done echo $ARG1 echo $ARG2 script2.sh (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

7. Shell Programming and Scripting

Passing sql as parameter to unix function

Hi, I have a function which connects to the db and runs the sql. it works fine when I run it like: function "select empname from emp;" but when I try to pass the sql string to a variable which in turn in fed to the function , it throws error. please advise. Thanks, Arnie. (1 Reply)
Discussion started by: itsarnie
1 Replies

8. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

9. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

10. Shell Programming and Scripting

Passing command as a function parameter

Hi All, Just trying to implement the below shell script using AIX ksh shell. myfunc { eval "$*" } CMD='ls -la /etc/hosts | awk '{print $9"|"$5}'' myfunc $CMD Keeping getting "|}: not found" errors, any pointers would greatly be appreciated. Kind Regards Ed Please... (2 Replies)
Discussion started by: eo29
2 Replies
Struct(3)						User Contributed Perl Documentation						 Struct(3)

NAME
Inline::Struct -- Manipulate C structures directly from Perl. SYNOPSIS
use Inline C => Config => Structs => ['Foo']; my $obj = Inline::Struct::Foo->new; $obj->num(10); $obj->str("Hello"); myfunc($obj); __END__ __C__ struct Foo { int num; char *str; }; void myfunc(Foo *f) { printf("myfunc: num=%i, str='%s' ", f->num, f->str); } This complete program prints: myfunc: num=10, str='Hello' DESCRIPTION
Inline::Struct is not a new language. It's a language extension designed to be used by Inline::C. It parses struct definitions and creates typemaps and XS code which bind each struct into a Perl class. This code is passed to Inline::C, which compiles it in the normal way. NOTE: Inline::Struct parses only C-style structs. It doesn't know about any C++ extensions to structs like scopes, constructors or methods. If you want such functionality you should use Inline::CPP to parse your structs. Using Inline::Struct Inline::Struct has a Parse::RecDescent grammar to parse C structs. If a struct is recognized, it can be bound to Perl. If the struct's definition is not recognized (usually because it has a member with no typemap), it will not be bound to Perl, but will be available from other functions in C or C++. The following example shows how a simple struct might look to a Perl programmer. Example 1: use Inline C => <<'END', ENABLE => 'STRUCTS'; struct Fraction { long numer; long denom; }; END my $o = Inline::Struct::Fraction->new(4, 3); print $o->numer, $o->denom, " "; $o->numer(4)->denom(7); After the code above has been compiled, Perl's namespace looks a lot like the following: package Inline::Struct::Fraction; sub new { } sub DESTROY { } sub _KEYS { } sub _VALUES { } sub _HASH { } sub numer { } sub denom { } Note that these are actually XS subs written in C, not Perl subs. But that's what it looks like. The Struct Interface The following sections define the interface of each subroutine. Note: this interface is likely to change in future versions of Inline::Struct. Please don't rely on Inline::Struct in production code quite yet. When a struct is bound by Inline::Struct, a new namespace is created underneath Inline::Struct. So if you have a struct named 'Foo', the package of the Perl class will be 'Inline::Struct::Foo'. new If no arguments are provided, all fields are zeroed out. If you provide values, they should be appropriate for the field type, and in the same order as they are defined in the struct. DESTROY The destructor. Should never be called by the programmer -- this is called automatically when the Perl variable holding the struct is destroyed. Frees the memory associated with the struct. If the struct holds pointers to malloc'd memory, they will not be freed. If you run into such a situation, consider using C++ and Inline::CPP instead. _KEYS A read-only method, this returns a reference to an array containing the names of the fields in the struct. The fields are in the order they appear in the C source code. _VALUES A read-only method, this returns a reference to an array containing the values of the fields in the struct. The values are returned in the same order as the fields. _HASH A read-only method, this returns a reference to a hash, mapping field names to field values. Accessors For each field in the struct, an accessor sub will be created which lets you get or set the value in the struct. If no arguments are provided, the sub returns the value of that field. If any arguments are provided, the field is set to the first argument, and the modified structure is returned. This makes setting multiple fields easy: $o->field1(something)->field2(somethingelse); C and C++ Configuration Options Inline::Struct has no configuration options of its own, but it does provide a new configuration option for C or C++. STRUCTS Specifies that structs are to be bound to Perl. There are several meanings to this option, so I'll explain with an example: use Inline C => Config => STRUCTS => 'Foo'; Adds 'Foo' to the list of structs to bind to Perl. use Inline C => Config => STRUCTS => ['Foo', 'Bar']; Adds 'Foo' and 'Bar' to the list of structs to bind to Perl. use Inline C => Config => STRUCTS => undef; Clears the list of structs to bind to Perl. use Inline C => Config => ENABLE => 'STRUCTS'; or use Inline C => Config => STRUCTS => 1; Enable binding structs to Perl, without specifying any structs to search for. As shown, this would bind all structs to Perl. use Inline C => Config => DISABLE => 'STRUCTS'; or use Inline C => Config => STRUCTS => 0; Disable binding structs to Perl. SEE ALSO
For more information about using C from Perl, see Inline::C. For more information about using C++ from Perl, see Inline::CPP. AUTHOR
Neil Watkiss (NEILW@cpan.org) COPYRIGHT
Copyright (C) 2001, Neil Watkiss. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. (see http://www.perl.com/perl/misc/Artistic.html) perl v5.18.2 2001-05-13 Struct(3)
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy