What are the drawbacks of declaring an array of string references in C? menu

User Tag List

Results 1 to 1 of 1
  1. #1
    YreiauW's Avatar Active Member
    Reputation
    19
    Join Date
    Jul 2022
    Posts
    9
    Thanks G/R
    2/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What are the drawbacks of declaring an array of string references in C?

    Is it harmful to declare an array of pointers to string literals if it is not defined as a constant?

    I'm constructing an array of strings of varied lengths. Everything appears to function OK if I set these up as an array of pointers to string literals, and I can even alter them afterward. I simply want to make sure this is the best technique before using it on a wider scale in an embedded program.

    • Is there any detrimental side effect that this basic example may have overlooked?
    • Is there any advantage to expressing it as a two-dimensional array of characters with a max length?

    Example:
    Code:
    #include <stdio.h>
    
    char * OutputNames[20] = 
    {
        "Output 01",
        "Output 02",
        "Output 03",
        "Output 04",
        "Output 05",
        "Output 06",
        "Output 07",
        "Output 08",
        "Output 09",
        "Output 10",
        "Output 11",
        "Output 12",
        "Output 13",
        "Output 14",
        "Output 15",
        "Output 16",
        "Output 17",
        "Output 18",
        "Output 19",
        "Output 20",
    };
    
    char main()
    {
        OutputNames[12] = "Test Output";
        for (unsigned char ArrMem = 0; ArrMem < 20; ++ArrMem)
        {
            printf("%s\n", OutputNames[ArrMem]);
        }
        
        getchar();
        return (0);
    }
    Scaler has one similar example online where they state String literals in C are read-only (despite the fact that their type is really char [].
    It also states that the array length is omitted so that the size may be determined by the initializer. I'm not sure what that means literally. Could someone please explain this to me?

    What are the drawbacks of declaring an array of string references in C?

Similar Threads

  1. What are the chances of getting banned for buying an RBG boost?
    By borab in forum World of Warcraft General
    Replies: 5
    Last Post: 03-21-2018, 01:04 PM
  2. what are the consequences of bots and hacks?
    By marcspc in forum World of Warcraft General
    Replies: 16
    Last Post: 03-12-2010, 09:13 PM
  3. What are the limitations of Model Editing?
    By Menasor in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 05-26-2009, 02:38 PM
  4. Also, what are the possibilities of adding a shapeshift?
    By Watercycle in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 03-09-2009, 05:14 PM
  5. what are the risks of gold scamming
    By Liquid Malfunction in forum WoW Scams Help
    Replies: 1
    Last Post: 10-22-2008, 03:16 PM
All times are GMT -5. The time now is 09:43 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search