Can't create float array with a variable name as size parameter?

Hi,
When trying to compile code that users a variable in the array subscript to set the size, CC gives the following error:
Error: An integer constant expression is required within the array subscript operator.
1 Error(s) detected.The code is as follows:
int main()
//blah blah
const int arrSize = numberVariables;
    float tempArr[arrSize];
//blah blah
}Output from CC -V:
unknown% CC -V
CC: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25Output from uname -a:
unknown% uname -a
SunOS unknown 5.10 Generic_137138-09 i86pc i386 i86pcAny ideas on why CC is giving that error?
~Slow
Edited by: SlowToady on Nov 15, 2008 8:28 PM
Edited by: SlowToady on Nov 15, 2008 8:36 PM

Marc_Glisse wrote:
Last time I checked, I did not see VLAs in the draft of the next C++ standard, which I believe is now feature complete. So either I missed it (quite possible) or VLAs were considered a bad idea (for C as well many people consider alloca and VLA bad ideas). It is however a very reasonable extension to have (care to file a RFE?).The following code performs like this on an IBM x366 with 4 single-core 3.16 GHz Xeons, running OpenSolaris build 96:
-bash-3.2$ ./thrtest
malloc() took 440895924 ns
alloca() took 2122522 ns
-bash-3.2$Using alloca is two hundred times faster.
Two hundred times faster.
Think about that next time some pedant says alloca "sucks".
Try for yourself. Here's the code:
#include <stdlib.h>
#include <pthread.h>
#include <alloca.h>
#include <strings.h>
#include <stdio.h>
#define NUM_THREADS 8
#define ITERS 10000
#define BYTES 1024
typedef void ( *mem_func_t )( void );
void alloca_iter()
    char *ptr;
    ptr = ( char * ) alloca( BYTES );
    memset( ptr, 0, BYTES );
    return;
void malloc_iter()
    char *ptr;
    ptr = ( char * ) malloc( BYTES );
    memset( ptr, 0, BYTES );
    free( ptr );
    return;
void *thread_proc( void *arg )
    mem_func_t mem_iter;
    mem_iter = ( mem_func_t ) arg;
    for ( int ii = 0; ii < ITERS; ii++ )
        mem_iter();
    return( NULL );
int main( int argc, char **argv )
    pthread_t tids[ NUM_THREADS ];
    void *results[ NUM_THREADS ];
    hrtime_t start;
    hrtime_t end;
    int ii;
    start = gethrtime();
    for ( ii = 0; ii < NUM_THREADS; ii++ )
        pthread_create( &tids[ ii ], NULL, thread_proc, malloc_iter );
    for ( ii = 0; ii < NUM_THREADS; ii++ )
        pthread_join( tids[ ii ], &results[ ii ] );
    end = gethrtime();
    printf( "malloc() took %ld ns\n", end - start );
    start = gethrtime();
    for ( ii = 0; ii < NUM_THREADS; ii++ )
        pthread_create( &tids[ ii ], NULL, thread_proc, alloca_iter );
    for ( ii = 0; ii < NUM_THREADS; ii++ )
        pthread_join( tids[ ii ], &results[ ii ] );
    end = gethrtime();
    printf( "alloca() took %ld ns\n", end - start );
    return( 0 );
}

Similar Messages

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • Newbie :  How can i create 2 users with the same name on diff domain name ?

    I have two domains on my server
    exemple1.com
    exemple2.com
    and i want to create one user for each domain with the same name
    [email protected] and [email protected]
    curently i can create one user, and it's the same user for both domains :-/
    how ?
    thanks
    Hète

    I must say. I am equally curious about this. i've played a lot in Communigate and it is easy to do there but how does one do this in apple mail?

  • How to create a PDF with a variable name

    I am a new user and i need a suggestion.
    I need to create a PDF file with a name that is a variable.
    I extract some data from SAP and i want use the "Offer number" to call my file.
    Wher i have to past my "variable" to the OutputFileName?
    Thanks
    Jeix

    This isn't an Output Designer question but an Output Server question. Anyway, see the subject titled "Dynamic pdf filename creation from form data content", currently about 13 subjects before yours.
    http://www.adobeforums.com/webx/.59b585c2/0

  • Can I create a database with the same name and DBID that one is dropped?

    Hello,
    I need to restore a backup database, made with Oracle Enterprise Manager, in a new one, because the original is dropped. I've tried it with the recovery tools but fails, i suppose because the dbid's are not the same.
    Then, Is it possible create a new database with the same old database dbid to restore de backup?
    Thank you very much.
    P.D.: I've too THE OLD spfile---.ora y el pwd---.ora

    I think you are using the same Composition Class on both project. On the properties tab, you can change this number (e.g.: EDGE-1637270).

  • Creating many arrays with different names

    I'm trying to create many arrays with a different names by calling this method:
    n=name of array
    c= some string
    public Array[] newArray(String n, String c)
    n[n.length]= new String();
    n[n.length]= c;
    As you experts might guess this does not compile. Is it even possible to do this?

    no, you cannot make a dynamic variable like that.
    and no, that is not the way to make arrays.
    and no, there is no such thing as "Array[]" ( unless u have made an "Array" object ).
    code for a new array is as such
    public Object[] newArray(int size){
      return new Object[size];
    }called as such:
    String[] strings = (String[]) newArray(10);
    strings[0] = "hmmm";mmmmm

  • How to create a array with variables dimensions?

    I try to create a array like that:
    Object[][] data;
    data = new Object[] [];
    But that's doesn't work!
    Apparently I must specify the dimension of my array
    So I have done like that :
    Object[][] data;
    data = new Object[3] [3];
    And that work!
    But the problem is when I need to add extra elements to my array.
    If I write :
    data[4][1] = "123";
    I have the error message :
    java.lang.ArrayIndexOutOfBoundsException
    So, how can I defined a array with variables dimensions OR how can I add a dimension to a array?

    if you have:
    Object[][] data;
    data = new Object[3] [3];you end yo getting ArrayIndexOutOfBoundException if you try to point to some other Indexes. You can increase the size by doing new:
    Object[][] data;
    data = new Object[4] [3];and then copy the old Arrays to this one... this is heavy.
    Other thing to consider then is using some other datastructure, such as Vector, which grows along you add elements to it.
    P_trg

  • How to create an array containing shared variable values

    Hi
    I am trying to programmatically create an array containing shared variable values and their names.  I can get the variable names by supplying the process name to the get shared variable list function.  How do I then read the value of all the shared variable items returned?
    I have used a data socket open to open a connection to all variables when my program starts.  I then use datasocket read on the opened connections to write to an array.  This works fine until I try to write to one of the variables using a shared variable node.  The variables writes can take from 4secs to 2 mins.  When I remove the shared variable node again all is fine.  Also when I stop using the data sockets, all is fine.
    Is there a conflict between shared variable nodes and data socket writes to the shared variables?
    Can anyone help?  I cannot easily post example code because I am reading the variables from a Wago PFC (PLC) using OPC.

    Hi
    Sorry I forgot to mention the LabVIEW version, its 8.20.  I have tried saving the shared variable node as a sub VI and it makes no difference.
    Attached is a stripped down version of the software.  You will not be able to connect to the IO server because it requires some Wago hardware and software.  You may spot something I have done wrong with the I/O servers, variables or sub VI's.
    The main program that runs is called 'HMI Engine' in the 'Framework' folder.  There may be some other things in the project that aren't used in this example.  I have removed all but the variable connection part of the code.
    I hope someone can help!?
    Thanks
    Mark.
    Attachments:
    HMI Test.zip ‏144 KB

  • Is it possible to/how can I create an array of arrays in Labview 6i?

    I am trying to create a data structure based on a tree where each limb is an array of arrays and each of those arrays is an array of arrays...etc. My ultimate purpose of this is for multidimensional (infinite) data saving/data recovery.

    I suspect it won't work for your intended application, but here is an answer to your question:
    You can't create an array of arrays, because that would be the same as increasing the number of dimensions of the array. However, you can store an array in a cluster, then have an array of clusters with arrays in them. So, indirectly it is possible. This gives you the possibility of each array being a different size.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • How can i creat several rectangles with one draw rect.vi

    how can i creat several rectangles with one draw rect.vi? thanks
    Solved!
    Go to Solution.

    You can call it in a for loop, with an array of the rectangle coordinates you want to draw. Is this what you mean?
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    rectangle.png ‏11 KB

  • How to auto create a global variable with specific variable name in a global vi ?

    how to auto create a global variable with specific variable name in a global vi using lv ? Because i need to add a lot of global variable in this global vi. But you know, if  i manually add them , it will be a much time-costing work. So i want to use someway to auto generate ? Can i ?? Thanks a lot !

    Hi
    what aartjan is saying is the way for you. but you can develop an utility which will actually help you create global variables. To get the details on this just have a look at VI Scripting section on LAVA forum.
    But i would like you to suggest few things
    1. If your programs have so many global variables (Thats why u want utility) then you should take out some time to read about LabVIEW design patterns. I think if programmer follows these practicess he dont need a single global variable.
    2. Their are some other ways to achieve similar functionality as of global variables (Uninitialized Shift Registers, Single Element Qs and so on) but they are much faster than global variables.
    I am Attaching Whatever Resources i am having I will also attach the template of the design pattern i generaly use in short duration
    Message Edited by Tushar Jambhekar on 10-06-2005 07:33 PM
    Message Edited by Tushar Jambhekar on 10-06-2005 07:36 PM
    Tushar Jambhekar
    [email protected]
    Jambhekar Automation Solutions
    LabVIEW Consultancy, LabVIEW Training
    Rent a LabVIEW Developer, My Blog
    Attachments:
    LabVIEWDesignPatterns.zip ‏1505 KB
    Large_Code_Implementation.zip ‏522 KB
    Database Tests.zip ‏868 KB

  • How can i create  excel sheet with multiple tabs using utl file?

    how can i create excel sheet with multiple tabs using utl file?
    any one help me?

    Jaggy,
    I gave you the most suitable answer on your own thread yesterday
    Re: How to Generating Excel workbook with multiple worksheets

  • How can I create a solution with Livecycle

    I work for a high school and we have about 12 pdfs that we need parents to read/scroll through, then 10 (different) pages that we want them to print, complete and return to the school.  Finally, we want them to see a "Thank you, you have done all you have to do" type screen.  We want to make it as user friendly as possible so I was thinking...
    Reading pages, 1 at a time with next at bottom.
    Click next and it takes them on.  When they get to printing pages 1 print button prints all pages we need them to print. Click next, and it takes them to optional print pages.
    Click next and it says, thank you.
    How can I make this happen if I already have all the pdfs?
    Help please.
    John Dent
    [email protected]

    Thank you soo much.  A few questions?
    They weren't created in designer but could I just import all of them?
    How do "build the structure" for the naviagtion?
    Where/how do you add the script.
    Thanks again,
    John Dent
    Date: Fri, 30 Jul 2010 07:01:08 -0600
    From: [email protected]
    To: [email protected]
    Subject: How can I create a solution with Livecycle
    I assume that all of these PDFs were created in Designer. If so you can add any buttons that you want to appear on every page (Next, Previous) onto the Master page then there is script you can add to the buttons to actual move the pages (xfa.host.pageDown() and xfa.host.pageUp()). The Prin button can be added to the specific page and you can pass the page numbers that you want to print as a parameter to the print command. Lastly when you get to the last page and the click Complete you can display a messageBox with your Thank you message.
    Hope that helps
    Paul
    >

  • How can I create a query with tables in INFOSET?

    Dear Gurus,
    How can I create a query with tables in INFOSET?
    Just tables and fields INFOSET?
    Kind Regards,

    Hello
    Check following SCN Article for your understanding/reference:
    - [Using Infoset Query ,SAP Query and Quick Viewer|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/10eab7af-0e54-2c10-28a5-87b47adbe1a5]
    Regards
    JP

  • How can I create a query with web service data control?

    I need to create a query with web service data control, in WSDL, it's query operation, there is a parameter message with the possible query criteria and a return message contains the results. I googled, but cannot find anything on the query with web service. I cannot find a "Named Criteria" in web service data control like normal data control. In Shay's blog, I saw the topics on update with web service data control. How can I create a query with web service data control? Thanks.

    Hi,
    This might help
    *054.     Search form using ADF WS Data Control and Complex input types*
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html

Maybe you are looking for

  • Query Designer restricted key figures using a prompt value

    Hallo Experts, I would like to restrict key figures after user has beeen prompted to enter a date. I have 2 key figures: a) KF1, Date1 b) KF2, Date2 User should be prompted to select a specific date: e.g. 01/2011. After selecting/entering the prompte

  • Tried everything, but "Secured link to iTunes Store failed"

    Hi all, I so hope you can help! I can't connect to the iTunes Store, which also means I can't do any Home Sharing (this being my ultimate goal in solving my problem). I've got Windows 7 home edition, 64-bit, and the newest iTunes. Running diagnostics

  • Adding dropdown list in an Infotype

    Hi ABAP HR Gurus, Good day. Basically, I need to add a dropdown list in a standard Infotype.  Can you kindly provide the steps on how to accomplish this?  Do I still need to use Transaction PM01 for this?  Thank you very much! Best regards. Brando Ed

  • Abap-table access via JDBC

    Hello, we have a java-program, that accesses data via jdbc to a mysql-database. Now we want to migrate the mysql-table to abap-table. How can we access from the  java-program to theese migrated abap-tables via jdbc? Regards Oliver

  • How to open new Pages file format

    Sorry if this is already answered, but I upgraded to OS 10.9 on a new Mac and it upgraded Pages in iWork suite, and now I can't read the files on my older Mac running OS 10.7 and Pages (iWork '09).  I purchased iWork '09 so is there a workaround to s