#pragma pack(1)

In my project I have hundreds of structures that I need to verify if their members are probably aligned when I turn on #pragma pack(1). I have to do it by hand, but it's very time consuming. Are there any tools, flags that you can use to detect them?
Thanks,
Quang

I'm having a bit of an issue myself. I have a very large struct that has many repeating patters of fields, and a smaller struct I use to overlay as a "sliding window". This works well when all the members are char, but breaks down as soon as I include a number type.
I have tried using the -xmemalign=1s | 1i options to no success. I am setting #pragma pack(1), and I have also tried #pragma align 1 (structname). Nothing works.

Similar Messages

  • Pragma pack(1) - relocation Error

    Hi,
    I am trying to use the #pragma pack(1) with Forte C++.
    I do use the -misalign option both at compilation and link.
    However, when I use a in this context, a class with virtual functions I get compilation errors at code generation ("location counter not on word boundary"). I get rid of these by compiling in debug mode, but then when linking I got the following error :
    "ld: fatal: relocation error: R_SPARC_DISP32: file foo.o: symbol <unknown>: offset
    0xfd8ea37b is non-aligned" as many times as I have virtual functions in my class.
    Has anyone used virtual functions in classes compiled with pragma pack(1)? and faced the same problem ?
    Am I missing an option ?
    Is there a workaround ?
    Thanks in advance.

    We've had the same problem with #pragma pack(1).
    When a class or a struct is not 'plain old data' (POD), it packs with 'normal' alignment instead of pack(1) apparently.
    You can make the class 'POD' by:
    - removing constructors
    - removing private data
    Other functions (as operator overloaders) are allowed, as we found out by trail/error.
    Anyway, you will find out if you remove the constructor from your class (and make e.g. an operator overloader for the assignment operator) that the packing will work as expected.

  • #pragma pack not working

    Hi,
    I'm using the forte CC compiler (CC: Sun WorkShop 6 update 1 C++ 5.2 2000/09/11) on a SUNOS 5.6 Ultra 250).
    Iam trying to use the #pragma pack option and am not able to get desired results.
    Here is a small test case
    //===========================================================================
    // compiled with:
    // CC -misalign -g -o prg prg.cc
    // output:
    // Sizeof Class_1 = 8 (expected: 6)
    // Sizeof Class_2 = 6 (expected: 6)
    //===========================================================================
    #include <stdio.h>
    #include <stdlib.h>
    #pragma pack(2)
    class Class_1{
    public:
    int data_1;
    char data_2[2];
    Class_1(){}
    class Class_2{
    public:
    int data_1;
    char data_2[2];
    #pragma pack()
    main()
    printf("Sizeof Class_1 = %d (expected: 6)\n", sizeof(Class_1));
    printf("Sizeof Class_2 = %d (expected: 6)\n",sizeof(Class_2));
    //===========================================================================
    The size of Class_1 should be 6, but get a 8.
    The packing seems to work if the class or struct does not have a ctor.
    Looking thru Sun's web pages I found a bug fix for
    "4199924 pragma pack(x) does not work"
    for C++ v5.0. I am hoping this bug is fixed in v5.2 and that Iam not seeing this bug.
    Thanks
    Leonard

    OK, does anyone atleast encounter this problem with their forte CC compiler at all, is there some patch that fixes this.
    Thanks for responses in advance
    Leonard

  • #pragma pack(1) problem

    <PRE>
    Let's assume that variable with the size more than 1 byte is located in memomry
    at the address, wich is not divisible to this variable (short - 2 bytes,
    int - 4 bytes and so on).
    In this case if we are trying to work with this variable then we receive error and
    program stops it's work with message "Bus Error"
    Example
    Test.cc:
    #include <stdio.h>
    #pragma pack(1)
    struct DTest {
    char chD1;
    int nD1;
    char chD2;
    int nD2;
    #pragma pack()
    main () {
    struct DTest DT;
    printf ("sizeof (DTest) = %d \n", sizeof(struct DTest));
    printf ("ptrDT = %p \n", &DT);
    printf ("&nD1 = %p \n", &DT.nD1);
    DT.nD1 = 100;
    printf ("nD1 = %d \n", DT.nD1);
    -------------- test --------------------
    *) Create executalbe with the command:
    CC Test.cc -o Test
    *) Execute:
    ./Test
    *) Result of work:
    sizeof (DTest) = 10
    ptrDT = ffbef25a
    &nD1 = ffbef25b
    Bus Error
    &nD1 = ffbef25b ;; pointer to variable (int type) is not
    ;; aligned in memort at 4
    </PRE>

    By design, #pragma pack works only on POD structs, for two reasons. A non-POD class is likely to have an unpredictable layout, and vtable pointers should not be misaligned (it would kill performance on SPARC).
    In retrospect, restricting packing to POD structs is too severe, as in your example. CR 4494035, visible at [http://bugs.sun.com], requests the requirement to be loosened. This RFE has not yet been implemented.
    When the "packed" attribute was introduced, it allowed some non-POD structs to be packed, but not structs that have a vtable pointer.
    Edited by: clamage45 on Mar 29, 2010 8:38 AM

  • #pragma pack(1) error

    Hi,
    I use forte c++ 6 in Solaris 2.6, a error occurs when i use #pragma pack(1) with a class having contruction function as following:
    #pragma pack(1)
    class AClass
    public:
         AClass(int a);
         short ashort;
         int aint;
    #pragma pack()
    I get the wrong result : sizeof(AClass) =8 ;
    But if i only have non-contruction functions(not including virtual functions) , i get the right result: sizeof(AClass) =6
    thanks in advance.

    We've had the same problem with #pragma pack(1).
    When a class or a struct is not 'plain old data' (POD), it packs with 'normal' alignment instead of pack(1) apparently.
    You can make the class 'POD' by:
    - removing constructors
    - removing private data
    Other functions (as operator overloaders) are allowed, as we found out by trail/error.
    Anyway, you will find out if you remove the constructor from your class (and make e.g. an operator overloader for the assignment operator) that the packing will work as expected.

  • Gcc's pragma pack

    I have inherited some linux code which uses gcc's pragma pack(push, n) and pragma pack(pop).
    #pragma pack(push, n)
    #pragma pack(pop)
    When I try to compile this code using gcc on Solaris/sparc I get:
    warning: #pragma pack(push[, id], <n> is not supported on this warning: #pragma pack(pop[, id], <n> is not supported on this target
    Anyone know how I can get past this problem. Is there an equivalent pragma that I can use with gcc for Solaris/sparc. Or is there an way to use something equivalent and compile with Sun studio 11.
    Thanks in advance!

    Sun C and C++ do not support the push and pop extensions to #pragma pack. These extensions cause the compiler to remember previous values of pack on a pushdown stack, so that different include files (for example) can set and restore the pack value without interfering with each other.
    Without this extension, you have to keep track of and manage the packing value yourself.
    That is, suppose you have this sequence:
    #pragma pack (push, 2) /* position A */
    ... declarations using packing value of 2
    #pragma pack (pop) /* restore old pack value */
    You will instead have to know what packing value was in effect a posiiton A, and explicitly set that value instead of using "pop".
    In the most common usage, packing is the default value, and temporarily changed for a few declarations. In that case, you can use this sequence:
    #pragma pack (2)
    .. declarations using packing value of 2
    #pragma pack /* restore default pack value */

  • Is this krb5 file infected for things like fishing?

    /*
    * This file is auto generated. Please do not edit it.
    #ifndef __KERBEROS5__
    #define __KERBEROS5__
    /* This file is generated, please don't edit it directly. */
    #ifndef KRB5_KRB5_H_INCLUDED
    #define KRB5_KRB5_H_INCLUDED
    /* -*- c -*-
    * include/krb5.h
    * Copyright 1989,1990,1995,2001, 2003, 2007 by the Massachusetts Institute of Technology.
    * All Rights Reserved.
    * Export of this software from the United States of America may
    * require a specific license from the United States Government.
    * It is the responsibility of any person or organization contemplating
    * export to obtain such a license before exporting.
    * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
    * distribute this software and its documentation for any purpose and
    * without fee is hereby granted, provided that the above copyright
    * notice appear in all copies and that both that copyright notice and
    * this permission notice appear in supporting documentation, and that
    * the name of M.I.T. not be used in advertising or publicity pertaining
    * to distribution of the software without specific, written prior
    * permission. Furthermore if you modify this software you must label
    * your software as modified software and not distribute it in such a
    * fashion that it might be confused with the original M.I.T. software.
    * M.I.T. makes no representations about the suitability of
    * this software for any purpose. It is provided "as is" without express
    * or implied warranty.
    * General definitions for Kerberos version 5.
    * Copyright (C) 1998 by the FundsXpress, INC.
    * All rights reserved.
    * Export of this software from the United States of America may require
    * a specific license from the United States Government. It is the
    * responsibility of any person or organization contemplating export to
    * obtain such a license before exporting.
    * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
    * distribute this software and its documentation for any purpose and
    * without fee is hereby granted, provided that the above copyright
    * notice appear in all copies and that both that copyright notice and
    * this permission notice appear in supporting documentation, and that
    * the name of FundsXpress. not be used in advertising or publicity pertaining
    * to distribution of the software without specific, written prior
    * permission. FundsXpress makes no representations about the suitability of
    * this software for any purpose. It is provided "as is" without express
    * or implied warranty.
    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
    * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
    * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    #ifndef KRB5_GENERAL__
    #define KRB5_GENERAL__
    /* By default, do not expose deprecated interfaces. */
    #ifndef KRB5_DEPRECATED
    #define KRB5_DEPRECATED 0
    #endif
    #if defined(__MACH__) && defined(__APPLE__)
    # include <TargetConditionals.h>
    # if TARGET_RT_MAC_CFM
    # error "Use KfM 4.0 SDK headers for CFM compilation."
    # endif
    #endif
    #if defined(_MSDOS) || defined(_WIN32)
    #include <win-mac.h>
    #endif
    #ifndef KRB5_CONFIG__
    #ifndef KRB5_CALLCONV
    #define KRB5_CALLCONV
    #define KRB5_CALLCONV_C
    #endif /* !KRB5_CALLCONV */
    #endif /* !KRB5_CONFIG__ */
    #ifndef KRB5_CALLCONV_WRONG
    #define KRB5_CALLCONV_WRONG
    #endif
    #ifndef THREEPARAMOPEN
    #define THREEPARAMOPEN(x,y,z) open(x,y,z)
    #endif
    #define KRB5_OLD_CRYPTO
    #include <stdlib.h>
    #include <limits.h> /* for *_MAX */
    #include <stdarg.h>
    #ifndef KRB5INT_BEGIN_DECLS
    #if defined(__cplusplus)
    #define KRB5INT_BEGIN_DECLS extern "C" {
    #define KRB5INT_END_DECLS }
    #else
    #define KRB5INT_BEGIN_DECLS
    #define KRB5INT_END_DECLS
    #endif
    #endif
    KRB5INT_BEGIN_DECLS
    #if TARGET_OS_MAC
    # pragma pack(push,2)
    #endif
    #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 30203
    # define KRB5_ATTR_DEPRECATED __attribute__((deprecated))
    #elif defined _WIN32
    # define KRB5_ATTR_DEPRECATED __declspec(deprecated)
    #else
    # define KRB5_ATTR_DEPRECATED
    #endif
    /* from profile.h */
    struct _profile_t;
    /* typedef struct _profile_t *profile_t; */
    * begin wordsize.h
    * Word-size related definition.
    typedef unsigned char krb5_octet;
    #if INT_MAX == 0x7fff
    typedef int krb5_int16;
    typedef unsigned int krb5_ui_2;
    #elif SHRT_MAX == 0x7fff
    typedef short krb5_int16;
    typedef unsigned short krb5_ui_2;
    #else
    #error undefined 16 bit type
    #endif
    #if INT_MAX == 0x7fffffffL
    typedef int krb5_int32;
    typedef unsigned int krb5_ui_4;
    #elif LONG_MAX == 0x7fffffffL
    typedef long krb5_int32;
    typedef unsigned long krb5_ui_4;
    #elif SHRT_MAX == 0x7fffffffL
    typedef short krb5_int32;
    typedef unsigned short krb5_ui_4;
    #else
    #error: undefined 32 bit type
    #endif
    #define VALID_INT_BITS INT_MAX
    #define VALID_UINT_BITS UINT_MAX
    #define KRB5_INT32_MAX 2147483647
    /* this strange form is necessary since - is a unary operator, not a sign
    indicator */
    #define KRB5_INT32_MIN (-KRB5_INT32_MAX-1)
    #define KRB5_INT16_MAX 65535
    /* this strange form is necessary since - is a unary operator, not a sign
    indicator */
    #define KRB5_INT16_MIN (-KRB5_INT16_MAX-1)
    * end wordsize.h
    * begin "base-defs.h"
    * Basic definitions for Kerberos V5 library
    #ifndef FALSE
    #define FALSE 0
    #endif
    #ifndef TRUE
    #define TRUE 1
    #endif
    typedef unsigned int krb5_boolean;
    typedef unsigned int krb5_msgtype;
    typedef unsigned int krb5_kvno;
    typedef krb5_int32 krb5_addrtype;
    typedef krb5_int32 krb5_enctype;
    typedef krb5_int32 krb5_cksumtype;
    typedef krb5_int32 krb5_authdatatype;
    typedef krb5_int32 krb5_keyusage;
    typedef krb5_int32 krb5_preauthtype; /* This may change, later on */
    typedef krb5_int32 krb5_flags;
    typedef krb5_int32 krb5_timestamp;
    typedef krb5_int32 krb5_error_code;
    typedef krb5_int32 krb5_deltat;
    typedef krb5_error_code krb5_magic;
    typedef struct _krb5_data {
    krb5_magic magic;
    unsigned int length;
    char *data;
    } krb5_data;
    typedef struct _krb5_octet_data {
    krb5_magic magic;
    unsigned int length;
    krb5_octet *data;
    } krb5_octet_data;
    * Hack length for crypto library to use the afs_string_to_key It is
    * equivalent to -1 without possible sign extension
    * We also overload for an unset salt type length - which is also -1, but
    * hey, why not....
    #define SALT_TYPE_AFS_LENGTH UINT_MAX
    #define SALT_TYPE_NO_LENGTH UINT_MAX
    typedef void * krb5_pointer;
    typedef void const * krb5_const_pointer;
    typedef struct krb5_principal_data {
    krb5_magic magic;
    krb5_data realm;
    krb5_data *data; /* An array of strings */
    krb5_int32 length;
    krb5_int32 type;
    } krb5_principal_data;
    typedef krb5_principal_data * krb5_principal;
    * Per V5 spec on definition of principal types
    /* Name type not known */
    #define KRB5_NT_UNKNOWN 0
    /* Just the name of the principal as in DCE, or for users */
    #define KRB5_NT_PRINCIPAL 1
    /* Service and other unique instance (krbtgt) */
    #define KRB5_NT_SRV_INST 2
    /* Service with host name as instance (telnet, rcommands) */
    #define KRB5_NT_SRV_HST 3
    /* Service with host as remaining components */
    #define KRB5_NT_SRV_XHST 4
    /* Unique ID */
    #define KRB5_NT_UID 5
    /* PKINIT */
    #define KRB5_NT_X500_PRINCIPAL 6
    /* Name in form of SMTP email name */
    #define KRB5_NT_SMTP_NAME 7
    /* Windows 2000 UPN */
    #define KRB5_NT_ENTERPRISE_PRINCIPAL 10
    /* Windows 2000 UPN and SID */
    #define KRB5_NT_MS_PRINCIPAL -128
    /* NT 4 style name */
    #define KRB5_NT_MS_PRINCIPAL_AND_ID -129
    /* NT 4 style name and SID */
    #define KRB5_NT_ENT_PRINCIPAL_AND_ID -130
    /* constant version thereof: */
    typedef const krb5_principal_data *krb5_const_principal;
    #define krb5_princ_realm(context, princ) (&(princ)->realm)
    #define krb5_princ_set_realm(context, princ,value) ((princ)->realm = *(value))
    #define krb5_princ_set_realm_length(context, princ,value) (princ)->realm.length = (value)
    #define krb5_princ_set_realm_data(context, princ,value) (princ)->realm.data = (value)
    #define krb5_princ_size(context, princ) (princ)->length
    #define krb5_princ_type(context, princ) (princ)->type
    #define krb5_princ_name(context, princ) (princ)->data
    #define krb5_princ_component(context, princ,i) \
    (((i) < krb5_princ_size(context, princ)) \
    ? (princ)->data + (i) \
    : NULL)
    * Constants for realm referrals.
    #define KRB5_REFERRAL_REALM ""
    * Referral-specific functions.
    krb5_boolean KRB5_CALLCONV krb5_is_referral_realm(const krb5_data *);
    * end "base-defs.h"
    * begin "hostaddr.h"
    */

    Rachel may get back to you next week. Meanwhile I will add some comments.
    Firstly even if I understood the code I do not see anywhere in your original post any of the following
    #endif \* __KERBEROS5__ */
    endif \* __KER
    endif \*
    #endif /* __KERBEROS5__ */
    endif /* __KER
    So I am unable to see what you are trying to point out.
    *'''You may need to post a correction for one of your posts ?'''
    Secondly such discussions would normally be outside the scope of the forum and so it maybe worth asking on some malware or security related forum such as:
    * http://www.bleepingcomputer.com/forums/
    * http://www.malwarebytes.org/forums/
    * http://www.spywarewarrior.com/index.php
    * http://www.spywareinfoforum.com/
    Or ask on a Mac related site. Surely your OS provides security anyhow. *Why are you needing to try to obtain such a file from the internet ?
    As a general uneducated observation. If I see something like that I may wonder
    * Is the software I have that generates that file kosher ?
    * Could it be obfuscated code ? <br />Or indications that malicious obfuscated code is present somewhere ?
    ** I am guessing <br />'''/*any text */''' is a remark and not actioned <br /> '''\*''' that the * will act as a delimeter on a single line <br />The latter possibly harmless in in a config file but setting alarm bells off that something may be wrong.
    As you have asked the question it would be interesting to know the answer you get.
    Background info
    * http://en.wikipedia.org/wiki/Kerberos_%28protocol%29
    * http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html
    *https://developer.mozilla.org/en-US/docs/Integrated_Authentication

  • How to pass a struct to a DLL function and accessing it in another VI

    Hi friends,
                       I am new to labview. I need to create a demo program in labview ,for displaying image from our own image capturing system. We have a  DLL ( build in VC++) containing functions for capturing image from our system. Now I need to create a VI library for some of functions in DLL and Create a Demo program using those created subvi library . I used "Call Function node" and created some of subvi's.
     Some of our DLL functions need to pass struct pointers.  Our function prototype will be similar to the following function.
    __declspec(dllexport) int __stdcall Initialize( unsigned char *imagebuffer,struct config *Configuration);
    The passed struct is similar to
    struct config
      double                val1[3];
      unsigned short   val2;
      bool                    val3;
      bool                    val4[3];    
      unsigned char    val5;    
      unsigned char   val6[3];
      bool                    val7[26];
    For passing "unsigned char *imagebuffer"  I initialized array with "Numeric constant " and set the size of the array and send to the function.
    The problem here is, I used this array in one of the subvi. 
    How can I use the returned imagebuffer array  in my main demo program. How to connect the image array to subvi "Connecter Pane"
    And  which control  can I use to display the image. The image data I get is form of 1-D Array .
    The second problem is,
                                 For passing the structure,  I used "Bundle " and filled the bundle with all the datatypes as in my struct and passed to the function. Is it correct ?  How to access this bundle after returned from function  in another Vi. ie.) How to connect this bundle to the connter pane ?
    Thanks for your valuable suggestions.
    aajjf.
    Message Edited by aajjf on 04-19-2007 05:34 AM

    aajjf wrote:
    Hi friends,
                       I am new to labview. I need to create a demo program in labview ,for displaying image from our own image capturing system. We have a  DLL ( build in VC++) containing functions for capturing image from our system. Now I need to create a VI library for some of functions in DLL and Create a Demo program using those created subvi library . I used "Call Function node" and created some of subvi's.
     Some of our DLL functions need to pass struct pointers.  Our function prototype will be similar to the following function.
    __declspec(dllexport) int __stdcall Initialize( unsigned char *imagebuffer,struct config *Configuration);
    The passed struct is similar to
    struct config
      double                val1[3];
      unsigned short   val2;
      bool                    val3;
      bool                    val4[3];    
      unsigned char    val5;    
      unsigned char   val6[3];
      bool                    val7[26];
    For passing "unsigned char *imagebuffer"  I initialized array with "Numeric constant " and set the size of the array and send to the function.
    The problem here is, I used this array in one of the subvi. 
    How can I use the returned imagebuffer array  in my main demo program. How to connect the image array to subvi "Connecter Pane"
    And  which control  can I use to display the image. The image data I get is form of 1-D Array .
    The second problem is,
                                 For passing the structure,  I used "Bundle " and filled the bundle with all the datatypes as in my struct and passed to the function. Is it correct ?  How to access this bundle after returned from function  in another Vi. ie.) How to connect this bundle to the connter pane ?
    Thanks for your valuable suggestions.
    aajjf.
    Message Edited by aajjf on 04-19-2007 05:34 AM
    You say nothing about how your cluster looks but I'm afraid you did the standard error here and placed arrays in it. That is not what the C structure is representing for several reasons.
    First fixed size arrays in C are inlined inside a structure, so are not a pointer but for the case of your val1 element three doubles.
    Second although not relevant here because of above point: LabVIEW arrays are not the same as C arrays. LabVIEW uses a pointer to a pointer and has the size of the array in elements prepended to the array data. C simply uses a pointer and all the rest is the programmers sorrow. The Call Library Node does convert the top level element of variables you pass according to the type configuration of that parameter but does no conversion of internal elements at all. So passing clusters with anything like arrays or strings is always wrong unless the DLL is aware of the specific datatypes LabVIEW uses.
    Last but not least you can end up with alignment issues. Elements in structures are aligned by every C compiler to a certain value. This value can be defined by the programmer in the project settings or for Visual C through #pragma pack() statements in the C code. The alignment rule says that an variable is aligned to the smaller of the two values that are either a multiple of the variable element size or the alignment setting. Most 32bit code nowadays uses 8 bit default alignment but LabVIEW always uses 1 byte. In your case there is nothing to observe since the large variables are at the beginning. Otherwise you might have had to insert filler elements in the LabVIEW cluster.
    One last thing bool is a C++ type only. Its size is 1 byte and incidentially this is the same LabVIEW uses for Booleans.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Pass an error cluster in and out of a C/C++ dll?

    Hi all,
    I'd like to know if it is possible to pass a LabVIEW error cluster to a C/C++ function from a dll. This would greatly help error handling in the different VIs.
    I am able to access and modify the first two members of the error cluster; the error status and the error code, which are, respectively, boolean and integer. But I cannot modify the string. LabVIEW crashes completely doing so.
    I first define a structure in C++ like this:
    const int N = 512;
    #pragma pack(push,1)
    typedef struct lvcluster {
    bool status;
    int code;
    char source[N];
    } lvcluster;
    #pragma pack(pop)
    Then, I define a function that will access the members status, code and source:
    int TestCluster(lvcluster *err)
    err->code = 1;
    err->status = false;
    sprintf(err->source, 'Test');
    I then use LabVIEW's "Call Library Function" to call this dll's function. I have set the parameter "err" to "Adapt to Type" and "Handles by Value". Trying to write characters to the source array crashes LabVIEW.
    Is this possible at all? How should it be done?
    Thanks!

    Thanks all for the comments.
    I've been looking at extcode.h where I saw the defeninition of a LStrHandle. It seems to be a pointer to pointer to "character array":
    typedef struct {
    int cnt; /* number of bytes that follow */
    unsigned char str[1]; /* cnt bytes */
    } LStr, *LStrPtr, **LStrHandle;
    The "character array" is different than a C character array, see http://www.ni.com/white-paper/4877/en/#toc4
    The first 4 bytes contain a signed 32 bit integer representing the number of characters. There is no NULL-termination character.
     So the error structure should be something like this (modulo the size of boolean, thanks rolfk):
    const int N = 512;
    #pragma pack(push,1)
    typedef struct lvcluster {
    bool status;
    int32 code;
    LStrHandle source;
    } lvcluster;
    #pragma pack(pop)
    From there, I was able to access a LabVIEW string from C. But I am unable to modify any of it. I might be able to change the characters from an alreay allocated string, but resizing or even creating a new string crashes LabVIEW. As reported by others, manipulating these strings would require linking against labview's library to access the string manipulation functions, but this is not possible as the library must be independant of LabVIEW.
    The only last possible way I can think of is to allocate a new cluster inside the DLL. Then I might be able to change the string in it, and hopefully LabVIEW would pick it up. I don't know how LabVIEW manages its memory; would it garbage collect the input cluster that is not used anymore?
    Thanks for all the feedback.

  • Core Dump in Foccur32() due to Address Misalignment

    Hi,
    I am working on Tuxedo 11.1_RP090 with HP-UX IA64, and after a call to tpcall() there is a core dumped due to address alignment issue. The following is excerpt from gdb backtrace.
    <snip>
    Program terminated with signal 10, Bus error.
    BUS_ADRALN - Invalid address alignment. Please refer to the following link that helps in handling unaligned data: http://docs.hp.com/en/7730/newhelp0610/pragmas.htm#pragma-pack-ex3
    #0  0xc000000000211ab0:0 in _lwp_kill+0x30 ()
       from /usr/lib/hpux64/libpthread.so.1
    (gdb) db
    Undefined command: "db".  Try "help".
    (gdb) bt
    #0  0xc000000000211ab0:0 in _lwp_kill+0x30 ()
       from /usr/lib/hpux64/libpthread.so.1
    #1  0xc000000000178810:0 in pthread_kill+0x9d0 ()
       from /usr/lib/hpux64/libpthread.so.1
    #2  0xc0000000003f80e0:0 in raise+0xe0 () from /usr/lib/hpux64/libc.so.1
    #3  0xc00000001e5a2d80:0 in skgesigOSCrash () at skgesig.c:376
    #4  0xc00000001f666900:0 in kpeDbgSignalHandler () at kpedbg.c:1074
    #5  0xc00000001e5a3220:0 in skgesig_sigactionHandler () at skgesig.c:799
    #6  <signal handler called>
    #7  Foccur32 () at Foccur32.c:87
    #8  0xc00000001498c020:0 in _tmaff_delallflds () at affinity.c:725
    #9  0xc00000001498b570:0 in _tmaff_acall () at affinity.c:117
    #10 0xc00000001478f7a0:0 in _tpacall_internal () at tmacall.c:588
    #11 0xc0000000147a2a30:0 in _tpcall_internal () at tmcall.c:349
    #12 0xc0000000147a0ed0:0 in _tpcall_ () at tmcall.c:157
    #13 0xc0000000147a3790:0 in tpcall () at tmcall.c:474
    #14 0xc000000002a3bc90:2 in inline mtux_flags () at my_app.c:1078
    #15 0xc000000002a3bc80:2 in mtux_sync (l_name=<not available>,
        l_service=<not available>, l_request_buf=<not available>,
        l_request_buf_len=<not available>, l_response_buf=<not available>,
        l_response_buf_len=<not available>, l_flags=<not available>)
        at my_app.c:1215
    </snip>
    In Frame 15, there is a call to tpcall() as follows:-
    tpcall((char *)l_service,
                   l_request_buf,
                   l_request_buf_len,
                   l_response_buf,
                   l_response_buf_len,
                   mtux_flags(l_flags))
    From  there the tuxedo code gets called and Signal 10 is raised in Frame 7, inside Foccur32(). Since we do not have the code for Foccur32.c,
    it is difficult for us to determine which address data structure passed as input parameter to tpcall() is misaligned or is it some misaligned pointer in Foccur32() code.
    It would be helpful, if someone can guide as to which structure needs to be examined for possible misalignment.
    Can someone please let me know what can be done to know whether code causing issue at line no. 87 in Foccut32() comes from the parameters passed to tpcall()?
    I am not sure whether it is due to the parameters we pass or due to some internal data structure used by Foccur32().
    Message was edited by: 642aa413-1410-45b0-8534-b407133fb819

    Hi,
    From a quick look at the code in affinity.c I'm guessing that you have a memory corruption problem.  The fault is occurring while trying to access the Tuxedo META TCM, a header that Tuxedo associates with the request.  If you can create a simple reproducer I would suggest opening a support request and provide the reproducer.
    As always, if this is a new problem, what's changed in your environment or application?  Also what is the environment/configuration of your Tuxedo application?
    Regards,
    Todd Little
    Oracle Tuxedo Chief Architect

  • Error in float.h after upgrade to LabWindows 5.5

    After getting a new PC, I installed LabWindows 5.5. A project which has run sucessfully on previous versions now stops with a build error. The error is in the file C:\MeasurementStudio\cvi\include\ansi\float.h at the pragma line:
    #ifdef WIN32
    #pragma pack(pop)
    #endif
    The error says "float.h"(42,22) Pack pragma valid values are 1, 2, 4, 8, and 16."
    I dont understand this. The project has been compiling with no similar errors for the past 3 yrs on the previous version.

    kmagas writes:
    > Thanks for all the answers, but I am still very much in the dark.
    >
    > I found no instance of "pop" in any of my project files.
    >
    > I have no control over including float.h. Nowhere in my project files
    > do I explicitly include float.h, but I do have float variables, so I
    > can only assume that the CVI environment senses that it is needed and
    > includes it.
    >
    > I tried adding /D_PUSHPOP_SUPPORTED=1 to the compiler predefines, with
    > no luck.
    >
    > This new PC is the same OS as the old one, Windows 98 SE.
    As a workaround, you can copy the old float.h file from CVI
    501 into your CVI 55 tree (cvi/include/ansi/float.h). The
    only difference between the two files is the #pragma pack.
    This should still work and you can continue
    working on your
    program.
    If you have a little more time to investigate the problem, I
    suggest you try this quick test if you haven't done so
    already. Open float.h (from cvi/include/ansi/), search for
    the line containing #pragma pack(pop) i.e. the one giving
    you the error and add this line directly above it (inside
    the #ifdef WIN32 block):
    #pragma message pop
    Recompile your project and verify that you have a Warning:
    Message: in your Build Error Window for the line
    that you've just added. If the warning message doesn't read
    "pop" then it's been redefined to something else and you
    need to find out where.
    However, it is surprising that you haven't been able to find
    pop anywhere in your project when you searched through your
    project files. For one thing, it should've shown up in
    float.h where it gives you the error. Or did I misunderstand
    you?
    Hope this helps,
    Peter
    -- Peter Ilberg

  • Data alignment

    Which is the data alignment of Labwindows CVI compiler? Byte, word,
    double word or quad word? Is there a way to change it?
    thanks.

    I found the BOOL type occupies 4bytes instead of one BYTE. Hence declare BYTE in place of BOOL. Other date types does not have any influence.
    Chcek the structure size with BYTE instead of BOOL.... You will get what you want 
    #pragma pack(push,PLC_TO_HMI,1)//pop,1)//,MyPackedData,1) 
     typedef struct
                    INT16 ifMachineMode;
                    char sMessage[101];
                    char sAlaram[101];
                    BYTE bfAutoOn;
                    BYTE bfAutoDone;
                    float LoadArray[10000];
                    double DistanceArray[10000];
                    float TorqueArray[10000];
                    double AngleArray[10000];
                    float rfUnlockLoadResult;
                    double rfUnlockAngleResult;
                    INT16 ifUnlockPlotPoints;
                    INT16 ifTiltPlotPoints;
                    INT16 ifLockPlotPoints;
                    float rfLockLoadResult;
                    double rfLockAngleResult;
                    double rfSlipDistanceResult;
                    float rfTiltLoadResult;
                    INT32 ifAdLoad;
                    INT32 ifAdTorque;
                    BYTE bfPassMsg;
                    BYTE bfFailMsg;
                    INT16 ifCycleDone;
                    INT16 ifOkCount;
                    INT16 ifNgCount;
                    float rfCycleTime;
                    float rfCurrentLoad;
                    double rfCurrentDistance;
                    float rfCurrentTorque;
                    double rfCurrentAngle;
                    BYTE Blinker500;
    } PLC_TO_HMI;
    PLC_TO_HMI Plc2Hmi;

  • DLL Call works fine with 1 cluster input but bombs with 2

    I have some problems getting my DLL to work using 2 cluster inputs.
     I create a simple DLL (MS C++ Express 2010) with 1 cluster and 1 struct Input and everything works.
     If I add a second cluster/struct, Labview bombs and disappears, Even if it's the same structure definition and initialization inputs.
     I'm making sure I have the struct Boundries set to 1 byte.  
     Any ideas?
    Solved!
    Go to Solution.

     Not using the #pragma pack, just setting the option for structure boundry properties in VC.
     It's been on maximum debugging but it's still crashing.
     Attached vi is nothing fancy, just trying to get 2 inputs to work.
     Hopefully something simple I'm not doing correctly. Thanks.
    Attachments:
    dll_definition_new.cpp ‏1 KB
    Nozzle_IO_30b.vi ‏8 KB

  • C++ header implementation

    Hello,
    I've had this question before, but now I'm trying it from a new
    approach. THe first time I tried to implement this headerfile in
    LABVIEW 6.1 I tried a direct approach, but that didn't work out well.
    My project is to implement the GetParmType stucture from this headerfile into a LABVIEW application.
    The approach I'm trying at this moment is to build an array of 326 bytes, and fill this array with the data from my EEPROM.
    The first 64Bytes is :        
    char           
    Version[VERSION_LEN];
    the next 2 bytes are the:    unsigned short  DeviceId;
    (this is the DeviceInfoType structure)
    the next byte is:                unsigned char   NrChannels;
    then 2 bytes for:               unsigned short  NrPixels;
    and 1 byte for:           
          unsigned char   Sensor;
    (this is the DeviceConfigType
    the rest of the array should be filled with the ChannelParmType
    structure. The maximum devices that can be connected is 8 pieces, so
    this should be a loop that runs the 8 times.
    Can somebody help me with this? I have no idea how this is done or how to fill an array this way.
    The headerfile is attached.
    Many thanx
    Koert
    Attachments:
    avs_dll.h ‏61 KB

    Lycangeek wrote:
    The DeviceConfigType is a great example of what I mentioned before about the dangers of mapping C structures to LV...   typedef struct
        unsigned char   NrChannels;         // number of channels
    unsigned short 
    NrPixels;          
    // number of pixels
        unsigned char  
    Sensor;            
    // Sensortype
    } DeviceConfigType;
    Typically in C/C++, you are going to have the compiler set to a 4-byte alignment (this is the default for 32-bit Windows).
    I
    think Visual C (at least in version 6) uses a default alignement of 8
    byte. However variables are usually aligned to the lesser of the
    default alignement or the variable size. So I would hazard that this
    particular structure actually would take up 5 byte since Visual C will
    add a fill byte between NrChannels and NrPixels.
    However you are right that in my example I didn't account for padding
    at all. Another problem is that there will be three additional fill
    bytes after Sensor, to make the first float in the ChannelArray align
    on a four byte boundary.
    So this would probably mean that for the DeviceConfig we should copy
    out at least 7 bytes and add a fill byte between channels and pixels
    and the offset for the channel array should be 74 instead of 70. Also
    the array intialization should then be 330 instead of 326.
    There still are some uncertainities. Unless the #pragma pack(x)
    statement is in the header file (in this case not) you still can't be
    certain that the DLL was compiled with the default alignment, although
    it is quite likely.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • I need help understanding an alignment panic when calling mutex_init

    I am looking for help with a STREAM module that compiles and run under Solaris 10 on 32-bit and 64-bit Intel kernels but panics on a 64-bit Sarc kernel.
    I have isolated the panic to a data alignment issue when my init routine calls either the rwinit and mutux_init routines with a pointer to a krwlock_t or kmutex_t structure that is not 8 byte aligned.
    I am using "gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)" from the Solaris 10 install CD's with the following options:
    gcc -Wall -fno-builtin -ffreestanding -nodefaultlibs -fpcc-struct-return -D_KERNEL -mno-app-regs -g -m64 -mcpu=v9 -D_SYSCALL32 -D_SYSCALL32_IMPL -D_ELF64 -D__sparcv9cpu -DSYSACCT -DC2_AUDIT
    (I know some of these are redundant)
    I have 4 locks along with a variety of other members defined in a structure used to by my driver code. If I manually arrange the structure to keep the lock variables on 8 byte boundries the module loads without a panic. However, if I let gcc handle the alignment or specifiy "__attribute__ ((aligned (8)))" on the lock variable definition the module panics on entry to the kernel rw_init or mutex_init routine with a BAD TRAP type 34 alignment error.
    At this point I am lost. I'm guessing this is a gcc/sparcv9 issue but I have no idea how to code this properly. I'm hoping someone can help shed some light on the problem.

    I found the problem. A shared header had a "#pragma pack(1)" with no matching "#pragma pack()". This was causing gcc to pack everything after the include.
    I'm still a little unclear why my "__attribute__ ((aligned (8)))" on the actual variable did not override the pragma ??? but at least I found the culprit.

Maybe you are looking for

  • Relative path for .FLV

    Hi There, I'm having difficulty with an FLV video I want to show in my presentation. The path has to be relative which I assume means relative to the .swf file that launches it. So I add the .flv to a slide in my presentation and set the path as simp

  • Why these problems with one component?

    I'm going slowly and methodically but can't seem to get anywhere. I am working from a backup copy of my Web site. I first tried creating a fresh copy from the DVD backup file. In that case, as in all cases, almost every page has a bad link bug. I tho

  • How to query data from Oracle, MySQL, and MSSQL?

    For an environment consisting of Oracle 11g/12c enterprise edition, MySQL 5.7 community edition, and MSSQL 2008/2012 stanard/enterprise edition, is there any major issue using DG4ODBC to query data from all 3 platforms? Is there other free alternativ

  • Pls advice

    I am working in an MNC as xi consultant ...And I got an offer from one another mnc to work as an xi consultant .I have one doubt regarding my job offer and i think you can give me correct advice ...the req in my next company is in BPO sector and my d

  • Item level display in adobe forms..

    Hi all,          I have a problem on adobe forms....For my req. I have fields like delv no , delv item , matnr, Customer mat no, qty , batch no and split no to display in line item level...but for one delv no there are multiple batch and split no..If