Received: from PCH.mit.edu (18.7.21.50) by mail.efplus.com (192.168.0.8) with Microsoft SMTP Server (TLS) id 8.3.485.1; Thu, 30 Jul 2020 09:35:21 -0700 Received: from PCH.MIT.EDU (localhost.localdomain [127.0.0.1]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UGQrrK012092; Thu, 30 Jul 2020 12:27:12 -0400 Received: from outgoing-exchange-1.mit.edu (OUTGOING-EXCHANGE-1.MIT.EDU [18.9.28.15]) by PCH.mit.edu (8.14.7/8.12.8) with ESMTP id 06UGQr9T012089 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 12:26:53 -0400 Received: from oc11exedge2.exchange.mit.edu (OC11EXEDGE2.EXCHANGE.MIT.EDU [18.9.3.18]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UGPMnU012964 for ; Thu, 30 Jul 2020 12:25:30 -0400 Received: from w92expo32.exchange.mit.edu (18.7.74.44) by oc11exedge2.exchange.mit.edu (18.9.3.18) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 12:26:16 -0400 Received: from oc11exhyb7.exchange.mit.edu (18.9.1.112) by w92expo32.exchange.mit.edu (18.7.74.44) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 12:26:30 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.171) by oc11exhyb7.exchange.mit.edu (18.9.1.112) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 12:26:29 -0400 Received: from MWHPR13CA0017.namprd13.prod.outlook.com (2603:10b6:300:16::27) by SN6PR01MB5216.prod.exchangelabs.com (2603:10b6:805:c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20; Thu, 30 Jul 2020 16:26:28 +0000 Received: from CO1NAM03FT011.eop-NAM03.prod.protection.outlook.com (2603:10b6:300:16:cafe::4) by MWHPR13CA0017.outlook.office365.com (2603:10b6:300:16::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Thu, 30 Jul 2020 16:26:28 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (40.92.40.59) by CO1NAM03FT011.mail.protection.outlook.com (10.152.80.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.10 via Frontend Transport; Thu, 30 Jul 2020 16:26:27 +0000 Received: from DM6NAM10FT024.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::4d) by DM6NAM10HT186.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::311) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20; Thu, 30 Jul 2020 16:26:25 +0000 Received: from BYAPR02MB4055.namprd02.prod.outlook.com (2a01:111:e400:7e86::42) by DM6NAM10FT024.mail.protection.outlook.com (2a01:111:e400:7e86::268) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 16:26:25 +0000 Received: from BYAPR02MB4055.namprd02.prod.outlook.com ([fe80::e04e:e8e2:57be:7927]) by BYAPR02MB4055.namprd02.prod.outlook.com ([fe80::e04e:e8e2:57be:7927%7]) with mapi id 15.20.3216.034; Thu, 30 Jul 2020 16:26:25 +0000 From: Bob Blick To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 09:26:25 -0700 Subject: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AQHWZotc+nNhZovUu0iBK4Bhj1/IWQ== Message-ID: List-Help: List-Subscribe: , List-Unsubscribe: , Reply-To: Microcontroller discussion list - Public. Accept-Language: en-US Content-Language: en-US X-MS-Exchange-Organization-AuthAs: Anonymous X-MS-Exchange-Organization-AuthSource: TS500.efplus4.local X-MS-Has-Attach: X-Auto-Response-Suppress: All X-MS-Exchange-Organization-SenderIdResult: Pass X-MS-Exchange-Organization-PRD: mit.edu X-MS-TNEF-Correlator: acceptlanguage: en-US received-spf: Pass (protection.outlook.com: domain of outlook.com designates 40.92.40.59 as permitted sender) receiver=protection.outlook.com; client-ip=40.92.40.59; helo=NAM10-BN7-obe.outbound.protection.outlook.com; dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rvHPQ7m47tt7sgyWsYNSCAMJo00AJS+vjHW7d28cC9w=; b=BfizLOmwSiwb8cQ+2PkDJFqgo5D9s6b142MEw3lqty+d6BXxyhLSL0z9UQdfe7ZwqimzqnkyI1Vl64Yvqb979dPmtQP7ym8JoWH5yzsvH3QiCiW/ZmtO9Pw8cLwGuGQE/Fqct5BTzDPVLeXObMlo2JEKR8+TIkVGeGfeDrIFdlY+pezJ6EvxAF091yL3MqvKU7VfVPf63CU9kTME3t0c0Obv6t/7+Ltrh4Mavl4ubexTGNce+jLe6xDY4rIKOEC8fkMSRwEk5O3KaAILGz/HcaPqFcTpefrXpzeIugWXbm5/+UWJU8dqZDzm9ja+PY1NZRFRbwiJy1RKdcP0XcjLdg== authentication-results: spf=pass (sender IP is 40.92.40.59) smtp.mailfrom=outlook.com; mit.edu; dkim=pass (signature was verified) header.d=outlook.com; mit.edu; dmarc=pass action=none header.from=outlook.com; errors-to: piclist-bounces@mit.edu list-id: "Microcontroller discussion list - Public." list-post: x-beenthere: piclist@mit.edu x-mailman-version: 2.1.6 x-topics: [PIC] x-mime-autoconverted: from quoted-printable to 8bit by PCH.mit.edu id 06UGQr9T012089 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 I'm using a nice little HD44780 LCD library in an STM32 project, it works g= reat but I'm stuck with a variable scope problem that I can only seem to ma= ke worse because GCC is a bit stricter than I want it to be at this point. = Sorry if the code example doesn't wordwrap properly. If, somewhere in main() I create an instance of the LCD like this: Lcd_PortType ports[] =3D {LCD_D4_GPIO_Port, LCD_D5_GPIO_Port, LCD_D6_GPIO= _Port, LCD_D7_GPIO_Port}; Lcd_PinType pins[] =3D {LCD_D4_Pin, LCD_D5_Pin, LCD_D6_Pin, LCD_D7_Pin}; Lcd_HandleTypeDef lcd =3D Lcd_create(ports, pins, LCD_RS_GPIO_Port, LCD_R= S_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE); then I can use it like this: Lcd_cursor(&lcd, 1,6); but of course I can't do that from within another function since "lcd" only= exists in main() If I try to make it all global by creating lcd outside of main(), GCC doesn= 't like that because initializer elements must be constants and it doesn't = consider "ports" and "pins" to be constants. Not being a real C programmer this has stopped me in my tracks. If I was st= uck on a deserted island I would use this library as a basis for something = with ports and pins hardcoded, but I'm hoping a real expert would give me s= ome gentle help, which will certainly educate me about doing things the cor= rect way and also get me past this little hurdle. Thanks, Bob --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .