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 10:04:20 -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 06UGtw8o015681; Thu, 30 Jul 2020 12:56:04 -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 06UGtodG015663 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Jul 2020 12:55:50 -0400 Received: from w92exedge3.exchange.mit.edu (W92EXEDGE3.EXCHANGE.MIT.EDU [18.7.73.15]) by outgoing-exchange-1.mit.edu (8.14.7/8.12.4) with ESMTP id 06UGs8XS014608 for ; Thu, 30 Jul 2020 12:54:28 -0400 Received: from w92expo27.exchange.mit.edu (18.7.74.33) by w92exedge3.exchange.mit.edu (18.7.73.15) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Thu, 30 Jul 2020 12:55:08 -0400 Received: from oc11exhyb4.exchange.mit.edu (18.9.1.100) by w92expo27.exchange.mit.edu (18.7.74.33) with Microsoft SMTP Server (TLS) id 15.0.1365.1; Thu, 30 Jul 2020 12:55:32 -0400 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (104.47.45.52) by oc11exhyb4.exchange.mit.edu (18.9.1.100) with Microsoft SMTP Server (TLS) id 15.0.1395.4 via Frontend Transport; Thu, 30 Jul 2020 12:55:32 -0400 Received: from MWHPR04CA0052.namprd04.prod.outlook.com (2603:10b6:300:6c::14) by MN2PR01MB5775.prod.exchangelabs.com (2603:10b6:208:17a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 16:55:30 +0000 Received: from CO1NAM03FT061.eop-NAM03.prod.protection.outlook.com (2603:10b6:300:6c:cafe::de) by MWHPR04CA0052.outlook.office365.com (2603:10b6:300:6c::14) 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 16:55:30 +0000 Received: from mail-yb1-f177.google.com (209.85.219.177) by CO1NAM03FT061.mail.protection.outlook.com (10.152.81.47) 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:55:29 +0000 Received: by mail-yb1-f177.google.com with SMTP id y134so9537314yby.2 for ; Thu, 30 Jul 2020 09:55:29 -0700 (PDT) From: Manu Abraham To: Microcontroller discussion list - Public. Sender: "piclist-bounces@mit.edu" Date: Thu, 30 Jul 2020 09:55:15 -0700 Subject: Re: [PIC] Simple GCC question Thread-Topic: [PIC] Simple GCC question Thread-Index: AdZmk3fFoASHnKJ7QySbmlDYgMndgQ== Message-ID: References: List-Help: List-Subscribe: , List-Unsubscribe: , In-Reply-To: Reply-To: Microcontroller discussion list - Public. Accept-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: received-spf: Pass (protection.outlook.com: domain of gmail.com designates 209.85.219.177 as permitted sender) receiver=protection.outlook.com; client-ip=209.85.219.177; helo=mail-yb1-f177.google.com; dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=dmkGHsug0lBrAyZfSB213MMJ1sSMxOlL4cwP1wGXoPo=; b=ClgLY/ZLukITAgBvT38Zpyn+es085VMnhflwURdPhZt9PKwy2Q8Koe1f65L76qGXXr Z9CNhkYH2IPGxL9af73pPnOVHYuorvGsqMhB0LMRh06cN69ycGlxVnII06u8wVmwGtBO 9i33AVq9qji7D3rqhdzLRg59+IRMzYY+rN/ir7jgXgVxoIImD8TnXPLX0xLvTAC808zt n1LXAEepTz4wV9JJELJoENBqHIAON6tcwaOwsSTZ6Z5S4bKyxhvPX0kzMe/McsihAz1c fd5U6VpTy11aolPnBbWV4SDubmxkzIjibcJDqC2rQ79nwO8vlcdyq0lfdXV3Mw9Zdhd0 Hfkw== authentication-results: spf=pass (sender IP is 209.85.219.177) smtp.mailfrom=gmail.com; mit.edu; dkim=pass (signature was verified) header.d=gmail.com; mit.edu; dmarc=pass action=none header.from=gmail.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-received: by 2002:a25:1fd5:: with SMTP id f204mr6099163ybf.236.1596128128554; Thu, 30 Jul 2020 09:55:28 -0700 (PDT) x-topics: [PIC] x-mime-autoconverted: from quoted-printable to 8bit by PCH.mit.edu id 06UGtodG015663 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 On Thu, Jul 30, 2020 at 9:57 PM Bob Blick wrote: > > 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. > > 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_GP= IO_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= _RS_Pin, LCD_EN_GPIO_Port, LCD_EN_Pin, LCD_4_BIT_MODE); > Why I dislike opaque datatypes... Instead of copying objects to Lcd_create(), a pointer could have been used, storage could have been global, made static .. the variables appear to be for configuration purposes ? One way to do is make the lcd object global. Another way is to pass a lcd object pointer to whatever function you are calling, unless you need to access the lcd object from interrupt context. If you need access from interrupt context, the easier way is to have global storage. --=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 .