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 16:02:02 -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 06UMqftB001471; Thu, 30 Jul 2020 18:53:19 -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 06UMqfmA001468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 18:52:41 -0400 Received: from oc11exedge1.exchange.mit.edu (OC11EXEDGE1.EXCHANGE.MIT.EDU [18.9.3.17]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UMpHDt003374 for ; Thu, 30 Jul 2020 18:51:18 -0400 Received: from oc11exhyb4.exchange.mit.edu (18.9.1.100) by oc11exedge1.exchange.mit.edu (18.9.3.17) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 18:52:12 -0400 Received: from oc11exhyb7.exchange.mit.edu (18.9.1.112) by oc11exhyb4.exchange.mit.edu (18.9.1.100) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 30 Jul 2020 18:52:40 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.172) 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 18:52:40 -0400 Received: from DM5PR20CA0005.namprd20.prod.outlook.com (2603:10b6:3:93::15) by DM5PR01MB3305.prod.exchangelabs.com (2603:10b6:3:fd::7) 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 22:52:38 +0000 Received: from DM3NAM03FT055.eop-NAM03.prod.protection.outlook.com (2603:10b6:3:93:cafe::29) by DM5PR20CA0005.outlook.office365.com (2603:10b6:3:93::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 22:52:38 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (40.92.19.92) by DM3NAM03FT055.mail.protection.outlook.com (10.152.83.209) 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 22:52:37 +0000 Received: from DM6NAM11FT055.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::4f) by DM6NAM11HT047.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::341) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.31; Thu, 30 Jul 2020 22:52:37 +0000 Received: from BYAPR02MB4055.namprd02.prod.outlook.com (2a01:111:e400:fc4d::40) by DM6NAM11FT055.mail.protection.outlook.com (2a01:111:e400:fc4d::359) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20 via Frontend Transport; Thu, 30 Jul 2020 22:52:37 +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 22:52:36 +0000 From: Bob Blick To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 15:52:36 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AQHWZotc+nNhZovUu0iBK4Bhj1/IWakgur83 Message-ID: References: List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: 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.19.92 as permitted sender) receiver=protection.outlook.com; client-ip=40.92.19.92; helo=NAM11-DM6-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=U/GAsdLiy5dMZ5kF9AOiMmbTvBOtipE+lRqrrKNbahg=; b=IrKLwnMrnfXXQJMFrE/QL9qXZxpsElVnNJY29xaW2lFgA3lQ8Zn/4tbFpNEOyRyAb8rBgAUba1WFWoHWuAGaOV7ul3+aYTgI/Lhg9azlTtKprIo+ldO9m4ntWskPRJpJTdlUDd1uV+z8ErvzlrugR4oz9u9UUp73iwUbIvRB9NiqIBiVcrJQ+gHGkD6Fz+zVXVxa9YX4dLzDsK70//DHr/ARe9vtZkdljC/mmb2AyA2q5QImaBKEXnYQbnrhg6PN7/bRGYEWNYacqarfqa92l2ZoKUFBDZW1wG+ss6cvc6ex2O5UsGvezWiTOEL5HZ0boOXCb1QzW7GTZo00I/hd7g== authentication-results: spf=pass (sender IP is 40.92.19.92) 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 06UMqfmA001468 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Here's a copy of an email Wouter sent directly. I will need to read up on a= singleton. So much to learn! > I'm using a nice little HD44780 LCD library in an STM32 project, it works= great but I'm stuck with a variable scope problem that I can only seem to = make 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. You could switch to C++, which allows globals to be initialized at run-time ..... (but that comes with its own can of worms, so I never use that feature). I think your problem is solved by having a global pointer to your LCD object, which you assign its value after you created the LCD thingy in main. Just take care that nobody uses it before that time. If you want to look clever, you could make a singleton: a function that returns the lcd pointer. The first time it is executed, it creates the LCD thingy. Maybe the ports and pins must be static too, depending on whether the lcd thingy uses them after its creation. Lcd_HandleTypeDef * Lcd(){ static Lcd_HandleTypeDef * p =3D NULL; static lcd_thingy; if( p =3D=3D NULL ){ 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_thingy =3D Lcd_create(ports, pins, LCD_RS_GPIO_Port, LCD_RS_Pi= n, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE); p =3D & lcd_thingy; } return p; } --=20 Wouter "Objects? No Thanks!" van Ooijen --=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 .